Thread: how do a make my program calculate a test grade

  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    Huintsville, AL.
    Posts
    14

    how do a make my program calculate a test grade

    here is the test i made and it all checks out - now I need it to print out the grade made on the test after completion.

    how do I do this?
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    char Answer;
    
    
    
    cout<<"you will be givin a short Exam of 5 questions \n"<<endl;
    cout<<"Press enter after each question is answered \n"<<endl;
    cout<<endl;
    cout<<endl;
    do
    {
    cout<<"Question 1"<<endl;
    cout<<"where was Jason Born? \n\n"<<endl;
    cout<<endl;
    cout<<"(a) - Chicago?"<<endl;
    cout<<"(b) - Atlanta?"<<endl;
    cout<<"(c) - Pheonix?"<<endl;
    cout<<"(d) - Tucson?" <<endl;
    cin>>Answer;
    
    cin.get();
    
    if (Answer=='d')
    {
    cout<<"Thats Correct!"<<endl;
    }
    else
    cout<<"Try Again"<<endl;
    }while (Answer== 'a' || Answer=='b' || Answer=='c');
    
    do
    {
    cout<<"Question 2"<<endl;
    cout<<"Where did Jason go to highschool"<<endl;
    cout<<endl;
    cout<<"(a) Sahuaro ?"<<endl;
    cout<<"(b) Sabino ?"<<endl;
    cout<<"(c) Huntsville ?"<<endl;
    cout<<"(d) Santa Rita ?"<<endl;
    cin>>Answer;
    
    cin.get();
    
    if (Answer=='a')
    {
    cout<<"Right again!"<<endl;
    }else
    cout<<"try again"<<endl;
    }while (Answer=='b' || Answer=='c' || Answer=='d');
    
    do
    {
    cout<<"Question 3"<<endl;
    cout<<"Where does Jason go to College"<<endl;
    cout<<endl;
    cout<<"(a) UAH ?"<<endl;
    cout<<"(b) UNA ?"<<endl;
    cout<<"(c) Alabama A&M ?"<<endl;
    cout<<"(d) Athens Sate ?"<<endl;
    cin>>Answer;
    
    cin.get();
    
    if (Answer=='c')
    {
    cout<<"Your on a roll!"<<endl;
    }else
    cout<<"try again"<<endl;
    }while (Answer=='a' || Answer=='b' || Answer=='d');
    
    do
    {
    cout<<"Question 4"<<endl;
    cout<<"what is Jason's Major"<<endl;
    cout<<endl;
    cout<<"(a) Electrical Engineer ?"<<endl;
    cout<<"(b) Civil Engineer ?"<<endl;
    cout<<"(c) Computer Science ?"<<endl;
    cout<<"(d) Mechanical Engineer ?"<<endl;
    cin>>Answer;
    
    cin.get();
    
    if (Answer=='c')
    {
    cout<<"Yes-4 in a role!"<<endl;
    }else
    cout<<"try again"<<endl;
    }while (Answer=='a' || Answer=='b' || Answer=='d');
    
    do
    {
    cout<<"Question 5"<<endl;
    cout<<"What floor is the computer science office on ?"<<endl;
    cout<<endl;
    cout<<"(a) 1st floor ?"<<endl;
    cout<<"(b) 2nd floor ?"<<endl;
    cout<<"(c) 3rd floor ?"<<endl;
    cout<<"(d) Basement ?"<<endl;
    cin>>Answer;
    
    cin.get();
    
    if (Answer=='c')
    {
    cout<<"Yes- you have completed this test!"<<endl;
    }else
    cout<<"try again"<<endl;
    }while (Answer=='a' || Answer=='b' || Answer=='d');
    return 0;
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Indent your code.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Location
    Huintsville, AL.
    Posts
    14

    indinting code

    I indented but when I put the [code] tags in it lines everything up for some reason.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    So think about what you need to do! How would you do so outside of a program? Figure that out and translate that into code.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by jason007thomas View Post
    I indented but when I put the [code] tags in it lines everything up for some reason.
    Unfortunately, that is not a valid excuse. If you can't indent, we can't read your code. You need to fix that problem.
    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
    Registered User
    Join Date
    Dec 2009
    Location
    Huintsville, AL.
    Posts
    14

    for loop for count in my program

    So far I have this

    number correct (divided by) total questions = score
    Code:
     for(Answer = 0; Answer<5; Answer++)

    program needs to count number correct
    then divide total number into number of correct questions


    I'm thinking there should be something saying correct answer instead
    but I'm totally baffled right now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grade Program
    By Jbrubin in forum C Programming
    Replies: 2
    Last Post: 03-28-2011, 02:02 PM
  2. Replies: 2
    Last Post: 01-29-2011, 12:58 PM
  3. calcuate average test grade problem
    By syrup890 in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2008, 01:02 AM
  4. grade program code
    By jd7joe in forum C++ Programming
    Replies: 8
    Last Post: 11-18-2005, 04:48 PM
  5. Student Grade Program
    By Vinod Menon in forum C Programming
    Replies: 1
    Last Post: 05-31-2004, 12:32 AM