The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Stuck on Programming Assignment

Bricks88Bricks88 Registered User new member
edited March 2009 in Help / Advice Forum
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!

Bricks88 on

Posts

  • DJ-99DJ-99 Registered User regular
    edited March 2009
    I haven't programmed C++ in like 8 years, but didn't you declare double theta twice? Both up top and then in your for statement?

    Maybe I'm just making that up, but I didn't know you needed to put "double" in your for statement.

    DJ-99 on
  • Bricks88Bricks88 Registered User new member
    edited March 2009
    Thanks!! Now I am down to only 5 errors:
    (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.

    Bricks88 on
  • JoeUserJoeUser Forum Santa Registered User regular
    edited March 2009
    setprecision is one word

    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))
    );

    JoeUser on
  • Bricks88Bricks88 Registered User new member
    edited March 2009
    Wow thanks! Totally figured it out now and its working!! Thank you both so much. Now on to part 2...

    Bricks88 on
Sign In or Register to comment.