If Statement Question

This is a discussion on If Statement Question within the C++ Programming forums, part of the General Programming Boards category; Hello, I am working on a program to calculate the letter grade for a user once they put in their ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Question If Statement Question

    Hello, I am working on a program to calculate the letter grade for a user once they put in their grade as a decimal.
    When I try to use the program, the following messages appear:
    Code:
    grade.cpp: In function `int main()':
    grade.cpp:48: syntax error at end of input
    Here is my program, can anyone find what I am doing wrong?
    Code:
    #include <iostream>
    int main()
    {
    double x;
    cout << "Please Enter Percentage Rounded to the Nearest Hundredth of a Percent: " << endl;
    cin >> x;
    
    if (x >= 93)
    {cout << "Your Score of " << x << " is an A" << endl;}
    
    if (x <= 92.99 && x >= 90)
    {cout << "Your Score of " << x << " is an A-" << endl;}
    
    if (x <= 89.99 && x >= 87)
    {cout << "Your Score of " << x << " is a B+" << endl;}
    
    if (x <= 86.99 && x >= 83)
    {cout << "Your Score of " << x << " is a B" << endl;}
    
    if (x <= 82.99 && x >= 80)
    {cout << "Your Score of " << x << " is a B-" << endl;}
    
    if (x <= 79.99 && x >= 77)
    {cout << "Your Score of " << x << " is a C+" << endl;}
    
    if (x <= 76.99 && x >= 73)
    {cout << "Your Score of " << x << " is a C" << endl;}
    
    if (x <= 72.99 && x >= 70)
    {cout << "Your Score of " << x << " is a C-" << endl;
    }
    if (x <= 69.99 && x >= 67)
    {
    cout << "Your Score of " << x << " is a D+" << endl;
    }
    if (x <= 66.99 && x >= 63)
    {
    cout << "Your Score of " << x << " is a D" << endl;
    }
    if (x <= 62.99 && x >= 60)
    {
    cout << "Your Score of " << x << " is a D-" << endl;
    }
    if (x <= 59.99)
    {
    cout << "Your Score of " << x << " is an F" << endl;
    }
    I sure hope that someone can help me out.
    Thank you!

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    you are missing the brace that closes int main()
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Where's your close curly brace to end main()?

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    You don't need braces in if statements if it's just one statement. It'll make your code neater, and you'll reduce the risk of making errors.

    You should return 0 too! :O
    Last edited by Sentral; 11-06-2008 at 02:50 PM.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Indentation is your friend in situations like these!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    To make Elysia's point clearer:
    Code:
    #include <iostream>
    int main()
    {
        double x;
        cout << "Please Enter Percentage Rounded to the Nearest Hundredth of a Percent: " << endl;
        cin >> x;
    
        if (x >= 93)
        {
    	cout << "Your Score of " << x << " is an A" << endl;
        }
    
        if (x <= 92.99 && x >= 90)
        {
    	cout << "Your Score of " << x << " is an A-" << endl;
        }
    
        if (x <= 89.99 && x >= 87)
        {
    	cout << "Your Score of " << x << " is a B+" << endl;
        }
    
        if (x <= 86.99 && x >= 83)
        {
    	cout << "Your Score of " << x << " is a B" << endl;
        }
    
        if (x <= 82.99 && x >= 80)
        {
    	cout << "Your Score of " << x << " is a B-" << endl;
        }
    
        if (x <= 79.99 && x >= 77)
        {
    	cout << "Your Score of " << x << " is a C+" << endl;
        }
    
        if (x <= 76.99 && x >= 73)
        {
    	cout << "Your Score of " << x << " is a C" << endl;
        }
    
        if (x <= 72.99 && x >= 70)
        {
    	cout << "Your Score of " << x << " is a C-" << endl;
        }
        if (x <= 69.99 && x >= 67)
        {
    	cout << "Your Score of " << x << " is a D+" << endl;
        }
        if (x <= 66.99 && x >= 63)
        {
    	cout << "Your Score of " << x << " is a D" << endl;
        }
        if (x <= 62.99 && x >= 60)
        {
    	cout << "Your Score of " << x << " is a D-" << endl;
        }
        if (x <= 59.99)
        {
    	cout << "Your Score of " << x << " is an F" << endl;
        }

    [quote = "Sentral"]
    You don't need braces in if statements if it's just one statement. It'll make your code neater, and you'll reduce the risk of making errors.
    [/quote]
    Ehm, yes and no. The coding standard where I work says that you should always use braces, whether they are needed or not. The reason for that is that it's quite easy to have something like this:
    Code:
       if (x)
          do_something;
    and then add:
    Code:
       if (x)
          do_something;
          some_other;
    forgetting to add the braces around the conditional code, and of course, that goes wrong, because despite indentation, some_other is actually always executed.

    You should return 0 too! :O
    In C++, it's is allowed to omit the return statement if you want to return "SUCCESS".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Thank you all so much!

    Well, I tried ending with a curly bracket and sure enough, that was it!
    Thank you so much everyone, you saved me so much time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about break in switch statement
    By alone2002dj in forum C Programming
    Replies: 1
    Last Post: 12-09-2007, 07:42 PM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 05:51 AM
  3. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM

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