I am working on this assignment for my programming class and am just getting majorly stuck. The idea of the project is to view K as a number or as a plot. My equations are correct but now I am not getting anywhere. Not sure if someone can point me in the right direction, or offer a suggestion.
The following is my code:
#include <iostream>
#include <math.h>
#include <ctype.h>
#include <iomanip>
using namespace std;
const double W = 10;
const double L = 40;
const double PI = 3.14159;
int main ()
{
double k; //Spring Constant
double kr; //K rounded to 2 decimals
double thetar = 0; //The angle b/t the hypotenuse and the x length in radians
double theta = 0; //The angle b/t the hypotenuse and the x length in degrees
char mode;
cout << "Enter the letter 'N' to view the spring constant, k as a numeric value " << endl
<< "Enter the letter 'P' to view a plot of values for the spring constant, k: ";
cin >> mode;
mode = toupper (mode);
switch (mode)
{
case 'N':
cout << " \n ANG k " << endl
<< " ============= " << endl;
{
thetar = (theta * PI) / 180;
k = ( W * cos (thetar)) / (2 * L*(cos(thetar)+sin(thetar) - 1) * (1-sin(thetar))));
kr = floor(k * 100.0 + .5) / 100.0 + .01;
cout <<" "<< theta <<" "<< set precision(2) <<kr << '/t' << endl;
}
break;
case 'P':
cout <<"\n PLOT OF k VALUES OF THETA (listed) " << endl
<<"(One * represents each .01 past .6)" << endl
<<"============================================" << endl;
for (double theta = 15; theta <=40; theta ++ )
{
thetar = (theta * PI) / 180;
k = ( W * cos (thetar)) / (2 * L*(cos(thetar)+sin(thetar) - 1) * (1-sin(thetar))));
kr = floor(k * 100.0 + .5) / 100.0 + .01;
cout <<" "<< theta <<" ";
while( k > .6)
{
k=k-.01;
cout << "*";
}
cout << endl;
}
break;
}
return 0;
}
I keep getting the following errors:
34) : error C2059: syntax error : ')'
36) : warning C4258: 'theta' : definition from the for loop is ignored; the definition from the enclosing scope is used
31) : definition of 'theta' ignored
(18) : definition of 'theta' used
(36) : error C2065: 'set' : undeclared identifier
(36) : error C2146: syntax error : missing ';' before identifier 'precision'
(36) : error C3861: 'precision': identifier not found
(46) : error C2059: syntax error : ')'
I am working on the syntax errors, but not sure what I should be doing about the 'precision' identifier and theta being ignored. Any guidance at all would be appreciated!
Posts
Maybe I'm just making that up, but I didn't know you needed to put "double" in your for statement.
(33) : error C2059: syntax error : ')'
(35) : error C2065: 'set' : undeclared identifier
(35) : error C2146: syntax error : missing ';' before identifier 'precision'
(35) : error C3861: 'precision': identifier not found
(45) : error C2059: syntax error : ')'
Still wondering about what I should use instead of 'precision'? Its getting 2 errors so its either wrong or used incorrectly.
For the syntax errors, you're just using too many parentheses at the end. Just remove one.
Below I've sort of divided up your parethetical groups.
k = (W * cos (thetar))
/ (2 * L*
(cos(thetar)+sin(thetar) - 1) *
(1-sin(thetar))
);