Jump to content
  • Advertisement
Sign in to follow this  

Errors Help

This topic is 3027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have to create a program that prompts the user for a grade, which is then sent to a function to be validated that it is in the correct grade range, and then converted to a gpa value. I get a lot of errors, if anyone could help me out it would be greatly appreciated. heres my code, which is now between source tags because Zahlman is a nice guy:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
    int grade; //Input variable
    double gpa; //Output variable
    int continue; //Used for while loop
    //start of program output
    cout << "Would you like to enter a grade? (yes or no): ";
    cin >> continue;
    //Start of loop
    while (continue = "yes")
    cout << "Please input a grade value: ";
    cin >> grade;
    gpa = gpaConversion(grade);
    cout << "Your GPA is: " << gpa << "\n";
    return 0;

double gpaConversion()


Grade     Letter  GPA Description

90 - 100     A+   5.0 Outstanding

85 - 89      A    4.5 Outstanding

80 - 84      A-   4.0 Excellent

75 - 79      B+   3.5 Very Good

70 - 74      B    3.0 Good

65 - 69      C+   2.5 Pass

60 - 64      C    2.0 Pass

55 - 59      D    1.5 Conditional Pass

50 - 54      D-   1.0 Conditional Pass

Below 50     F    0.0 Fail*/

    //Validate grade and convert to GPA
    if (grade >= 89.5 && grade <= 100);
    gpa = 5.0;
    else if (grade >= 84.5);
    gpa = 4.5;
    else if (grade >= 79.5);
    gpa = 4.0;
    else if (grade >= 74.5);
    gpa = 3.5;
    else if (grade >= 69.5);
    gpa = 3.0;
    else if (grade >= 64.5);
    gpa = 2.5;
    else if (grade >= 59.5);
    gpa = 2.0;
    else if (grade >= 54.9);
    gpa = 1.5;
    else if (grade >= 49.5);
    gpa = 1.0;
    else if (grade >= 0);
    gpa = 0.0;
    else if (grade < 0 && grade > 100);
    gpa = "unavailable due to an incorrect grade value. Please enter a grade between 0 and 100.";   
    return gpa;  

Thank you!!! [Edited by - Zahlman on February 9, 2010 6:30:19 PM]

Share this post

Link to post
Share on other sites
Here's what you need to do if you want help.

1. Edit your post so that your code is surrounded by CODE /CODE tags or SOURCE tags.
2. Copy paste the errors you get here. We aren't psychics. We need that information to help you.
3. Tell us what you tried to fix your problem. You have errors. So, did you read the errors and fix the issue? if you didn't understand the error, did you Google one by one?

Be as specific in your inquiry as possible. If I you can't understand an error, asking for help is a meaningless inquiry.

Share this post

Link to post
Share on other sites
warning: ive only been learning for a few weeks

1) error int continue; //Used for while loop, you cant use the name continue as a variable as it is used by the compiler as a special keyword. you have to change the name of continue to somthing like cont for all instances in code

2) while (continue = "yes") - change continue to cont or something like that and also you have declared continue as a integer but now your using a string in it.

3) It think the way your trying to do the loop is wrong. basically you should do

while (boolean is true) do the following code and to get the boolean you could get user input and if user types 'y' or 'Y' set the value of boolean to true else false that way you can control the loop.

4) gpaConversion(grade); is not defined before main but should be before main as it is a prototype and should read something like "double gpaConversion(double grade =0);"

5) The actual function is not initialized properly. you have double gpaConversion() but it should be double gpaConversion (double grade) {code}

As i said at start ive only been coding for a few weeks so could be wrong and im sure ive missed more things but I hope it helps.

Kind Regards

Share this post

Link to post
Share on other sites
1) In C++, variables have types. When you write something like 'int foo;', you are promising that 'foo' will always be an integer value. Similarly, 'double bar;' promises that 'bar' will always be a floating-point value.

A string, such as "yes" or "unavailable due to an incorrect grade value. Please enter a grade between 0 and 100.", is not an integer nor a floating-point value. They therefore cannot be held in such variables.

You must think about what kind of data something is before you give it a name (i.e. assign it to a variable).

2) In C++, '=' always stands for assignment. It is never used for comparison - not even when you are doing 'if' logic. To compare if two things are equal, use '=='.

3) You can't name a variable 'continue', because it is one of the terms used by the language (just like 'int', or 'while').

4) Variables have scope. The variable 'gpa' belongs to the main function, because that's where it was declared. You cannot use it within the function gpaConversion. However, you can declare another variable there and use it. You can even call it 'gpa'. Each would be a separate variable.

5) When you write 'if (condition)', immediately after the '(condition)' comes the part that should happen when the condition is true. That can be a single statement, or it can be a block of statements inside {}. That is, the rules are exactly the same for 'if' as they are for 'while'. In C++, it is valid to have an empty statement - one with nothing in it at all. As you can imagine, it does nothing. If you write 'if (condition);', then what gets executed when the condition is true? Well, ';' is a statement separator, so the statement begins just after the ')' and ends just before the ';'. Yep, that's right: there's nothing in it. That's certainly not what you want; why check something if you're not going to do anything about it?

6) Please do not pause your programs artificially at the end (i.e. 'system("pause")'). Instead, learn to run them properly, e.g. from the command line, with a batch file, or with the appropriate configuration options in the IDE.

7) Look at error messages and read them. They do, in fact, describe the problems in the code. In English.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!