Help with easy errors!

This is a discussion on Help with easy errors! within the C++ Programming forums, part of the General Programming Boards category; Hey my name is Josh and I am new to C++. I have a simple project due in a week ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    9

    Help with easy errors!

    Hey my name is Josh and I am new to C++. I have a simple project due in a week and i cannot pinpoint two errors. If anyone can help that would be great.
    Code:
    #include <iostream>                // include standard I/O libraries
    #include <iomanip>
    using namespace std;
    
    int main ()
    {	
    	// the constant weights for all scoring items
    	const double P1_WEIGHT = 0.02;
    	const double P2_WEIGHT = 0.10;
    	const double P3_TO_P6_WEIGHT = 0.13;
    	const double EXAM_WEIGHT = 0.18;
    
    	int	p1score,                  // scores on the 6 programs
    		p2score,
    		p3score,
    		p4score,
    		p5score,
    		p6score,
    		exam1score,                // scores on the 2 exams
    		exam2score,
     double wtdTotalGrd;            // the weighted total grade as calculated
    
    	// write the main output heading
    	cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << endl;
    	cout << "Welcome to the Weighted Grade Calculator Program" << endl;
    	cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << endl << endl;
    
    	// ask the user to type in the program grades first
    	cout << "Please enter your score on program 1 -> ";
    	cin >> p1score;
    	cout << "                           program 2 -> ";
    	cin >> p2score;
    	cout << "                           program 3 -> ";
    	cin >> p3score;
    	cout << "                           program 4 -> ";
    	cin >> p4score;
    	cout << "                           program 5 -> ";
    	cin >> p5score;
    	cout << "                           program 6 -> ";
    	cin >> p6score;
    
    	// now ask the user to type in the exam scores
    	cout << endl << "Please enter your score on exam 1 -> ";
    	cin >> exam1score;
    	cout << "                           exam 2 -> ";
    	cin >> exam2score;
    
        // echoprint all of the user's scores to verify accuracy
    	cout	<< endl << "You have entered the following scores:" << endl;
    	cout	<< "\tProgram 1: " << p1score << endl;
    	cout	<< "\tProgram 2: " << p2score << endl;
    	cout	<< "\tProgram 3: " << p3score << endl;
    	cout	<< "\tProgram 4: " << p4score << endl;
    	cout	<< "\tProgram 5: " << p5score << endl;
    	cout	<< "\tProgram 6: " << p6score << endl;
    	cout	<< "\tExam 1: " << exam1score << endl;
    	cout	<< "\tExam 2: " << exam2score << endl << endl;
    
    	// calculate the weighted total grade as a real number
    	cout	<<    wtdTotalGrd = (p1score * P1_WEIGHT) + (p2score * P2_WEIGHT)[/B]
    		          + ((p3score + p4score + p5score + p6score) * P3_TO_P6_WEIGHT)
    				  + ((exam1score + exam1score) * EXAM_WEIGHT);
    
    	// now print the weighted total with 2 digits past the decimal point
    	cout << fixed << showpoint << setprecision(2);
    	cout << "Your weighted total is: " << wtdTotalGrd << endl;
    
    	// print a closing message and signal normal termination
    	cout << endl <<  "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=";
    	cout << endl << "Program Run Completed." << endl;
    	cout <<  "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
    
    	return 0;
    }
    here are the errors that I have:
    Error 1 error C2062: type 'double' unexpected 57

    Error 2 error C2065: 'wtdTotalGrd' : undeclared identifier 96

    Here are the lines where the errors are.
    double wtdTotalGrd; // the weighted total grade as calculated

    cout << wtdTotalGrd = (p1score * P1_WEIGHT) + (p2score * P2_WEIGHT)
    + ((p3score + p4score + p5score + p6score) * P3_TO_P6_WEIGHT)
    + ((exam1score + exam1score) * EXAM_WEIGHT);[/B]


    If anyone can help explain why these are errors that would be great. Thanks for the help
    Last edited by gtpgrandprix; 01-17-2008 at 06:56 AM.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    The first error:

    You have an enumeration of integer variables which is not terminated by a semi-colon.

    The second error is caused by the first one.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    Error 1 error C2062: type 'double' unexpected 57
    Take a careful look at this piece of code:
    Code:
    	int	p1score,                  // scores on the 6 programs
    		p2score,
    		p3score,
    		p4score,
    		p5score,
    		p6score,
    		exam1score,                // scores on the 2 exams
    		exam2score,
     double wtdTotalGrd;            // the weighted total grade as calculated
    Can you spot the error?

    The next error is related to this one, so fix this error first.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    You might want to use arrays, if you have learned how to use them.

    Code:
    int pscore[6];
    for(int i = 0; i < 6; i++)
    {
      std::cout << "Please enter your score on program " <<&#160;i <<&#160;": " << std::endl;
      std::cin >> pscore[i];
    }
    Instead of:
    Code:
    	cout << "Please enter your score on program 1 -> ";
    	cin >> p1score;
    	cout << "                           program 2 -> ";
    	cin >> p2score;
    	cout << "                           program 3 -> ";
    	cin >> p3score;
    	cout << "                           program 4 -> ";
    	cin >> p4score;
    	cout << "                           program 5 -> ";
    	cin >> p5score;
    	cout << "                           program 6 -> ";
    	cin >> p6score;

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    is it because I have (,) at the end of
    Code:
     p1score,                  // scores on the 6 programs
    		p2score,
    		p3score,
    		p4score,
    		p5score,
    		p6score,
    		exam1score,                // scores on the 2 exams
    		exam2score,
    instead of ;
    Last edited by gtpgrandprix; 01-17-2008 at 07:02 AM.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    Well try and remove it =)

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    Quote Originally Posted by Desolation View Post
    You might want to use arrays, if you have learned how to use them.

    Code:
    int pscore[6];
    for(int i = 0; i < 6; i++)
    {
      std::cout << "Please enter your score on program " << i << ": " << std::endl;
      std::cin >> pscore[i];
    }
    Instead of:
    Code:
    	cout << "Please enter your score on program 1 -> ";
    	cin >> p1score;
    	cout << "                           program 2 -> ";
    	cin >> p2score;
    	cout << "                           program 3 -> ";
    	cin >> p3score;
    	cout << "                           program 4 -> ";
    	cin >> p4score;
    	cout << "                           program 5 -> ";
    	cin >> p5score;
    	cout << "                           program 6 -> ";
    	cin >> p6score;
    I haven't learn arrays yet, thx tho

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    ah that wasn't it. What does "enumeration of integer variables which is not terminated by a semi-colon" mean?

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    903
    enumeration: serie of items separated by commas ','
    of integer variables: variables declared with the 'int' type
    which is not terminated by a semi-colon: all instructions in C++ need to be terminated with a semi-colon ';'

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    What does "enumeration of integer variables which is not terminated by a semi-colon" mean?
    The thing that I was trying to get you to see.

    You pretty much identified the problem. What did you try to solve it?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    ok I went back and put ( ; ) at the end of each interger and got more errors

    Code:
    int	p1score;                  // scores on the 6 programs
    		p2score;
    		p3score;
    		p4score;
    		p5score;
    		p6score;
    		exam1score;               // scores on the 2 exams
    		exam2score;
      double wtdTotalGrd;

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    everyone is really helpful thank you

  13. #13
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    "You have an enumeration of integer variables which is not terminated by a semi-colon"
    this means to that each interger needs a ';' at the end but its wrong?

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,639
    Your code snippet is now:
    Code:
    int p1score; // scores on the 6 programs
    p2score;
    p3score;
    p4score;
    p5score;
    p6score;
    exam1score; // scores on the 2 exams
    exam2score;
    double wtdTotalGrd;
    The problem is basically that you want to declare a few variables of the same type (e.g., int). You can do it like this:
    Code:
    int x, y;
    or you can do it like this::
    Code:
    int x;
    int y;
    But suppose you want to declare a variable of a different type (e.g., double). You can write it as:
    Code:
    int x, y;
    double z;
    or:
    Code:
    int x;
    int y;
    double z;
    But not as:
    Code:
    int x, y, double z;
    which is identical to:
    Code:
    int x, y,
    double z;
    or as:
    Code:
    int x; y;
    double z;
    which is identical to:
    Code:
    int x;
    y;
    double z;
    ... which is your new problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Registered User
    Join Date
    Jan 2008
    Posts
    9
    ok i see what your are saying is that i needed to end the (int) statement I did it like this
    Code:
    int	p1score,                  // scores on the 6 programs
    		p2score,
    		p3score,
    		p4score,
    		p5score,
    		p6score,
    		exam1score,                // scores on the 2 exams
    		exam2score;
      double wtdTotalGrd;           // the weighted total grade as calculated
    and now it works; however i've got a new error this
    Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const double' (or there is no acceptable conversion) 98
    Code:
    // calculate the weighted total grade as a real number
    	cout	<<    wtdTotalGrd = (p1score * P1_WEIGHT) + (p2score * P2_WEIGHT)[/b]
    		          + ((p3score + p4score + p5score + p6score) * P3_TO_P6_WEIGHT)
    				  + ((exam1score + exam1score) * EXAM_WEIGHT);

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. errors using my parser- MSVC++ 6, bhtypes.h
    By AeroHammer in forum C++ Programming
    Replies: 6
    Last Post: 01-25-2005, 06:11 PM
  3. opengl Nehe tutorial errors when compiling
    By gell10 in forum Game Programming
    Replies: 4
    Last Post: 07-14-2003, 08:09 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21