Help with program.

This is a discussion on Help with program. within the C++ Programming forums, part of the General Programming Boards category; Please, some one help. I am stuck with this simple program. I am taking the intro to C++ programming course ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Question Help with program.

    Please, some one help. I am stuck with this simple program. I am taking the intro to C++ programming course at sschool and my homework assignment calls for me to write a program. I know this may be simple for experienced programmers but I just can't get it.

    Here is the assignment:

    Write a grade calculation program that accepts the class level and test score and computes the grade according to the following formula:

    Class level Test Score Grade
    1,2,3,4 score>=60 Pass
    score < 60 Fail

    5,6,7,8 score >=75 Pass
    score <75 Fail

    9,10,11,12 score >=90 Pass
    score <90 Fail

    I would appreciate any help regarding this.
    Thanks.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Well, I'm not going to write the whole thing , but the pseudo code's kinda like this:
    Code:
    1)Input class level
    2)Input grade
    3)Use a switch structure or nested if statements to check on appropriate results
    4)Output pass or fail
    hth

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    10
    Thanks, I am having trouble with declaring the identifiers, it is the main thing that I get stuck with when writing code....it never fails that I will have trouble with that.
    Jimmy

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    The identifiers?

    Like

    int x = 0;

    ???

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    10
    yep, thanks though, I got the program to compile and run error free using the nested if statements, but I was trying to simplify it using the switch statement, I wrote a previous program for homework that had to calculate the change in quaters, dimes, nickesl and pennies for a given input from 0...99, so I wound up with about 100 lines of code. I had one if statement for each input because the out put would be different every time could this be simplified? Or not because of the different out put for every input? ie... 99 for input couts to 3 quaters, 2 dimes and 4 pennies.

    As far as the current program is concerned I got it to work the same way as the first, but with this one I am sure I can simplify it using a switch statement with break. Here it is:

    /*A grade calculation program that accepts a class
    level and test score and computes the grade.*/

    #include <iostream.h>

    void main ()
    {
    int answer, y, x;
    const int YES=1, NO=2;

    cout<<"Would you like to begin grade";
    cout<<" calculation?"<<endl;
    cout<<"(1 - YES, 2 - NO)"<<endl;
    cin>>answer;

    while (answer==YES) {
    cout<<"Please enter class level from 1";
    cout<<" - 12";
    cout<<" then press return."<<endl;
    cin>>x;

    cout<<"Please enter score and press";
    cout<<" return."<<endl;
    cin>>y;

    if(x<=4 && y>=60)
    cout<<"PASS"<<endl;

    else if(x<=4 && y<60)
    cout<<"FAIL"<<endl;

    else if(x<=8 && x>4 && y>=75)
    cout<<"PASS"<<endl;

    else if(x<=8 && x>4 && y<75)
    cout<<"FAIL"<<endl;

    else if(x<=12 && x>8 && y>=90)
    cout<<"PASS"<<endl;

    else if(x<=12 && x>8 && y<90)
    cout<<"FAIL"<<endl;

    cout<<"Do you wish to continue?"<<endl;
    cout<<"(1 - Yes, 2 - No)"<<endl;
    cin>>answer;
    }
    }
    Jimmy

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by jpad687
    Here it is:

    /*A grade calculation program that accepts a class
    level and test score and computes the grade.*/

    #include <iostream.h>

    void main ()
    {
    int answer, y, x;
    const int YES=1, NO=2;

    cout<<"Would you like to begin grade";
    cout<<" calculation?"<<endl;
    cout<<"(1 - YES, 2 - NO)"<<endl;
    cin>>answer;

    while (answer==YES) {
    cout<<"Please enter class level from 1";
    cout<<" - 12";
    cout<<" then press return."<<endl;
    cin>>x;

    cout<<"Please enter score and press";
    cout<<" return."<<endl;
    cin>>y;

    Right here you could do this to save steps:
    Code:
    cout << "Enter class level and score: ";
    cin >> x >> y;
    if(x<=4 && y>=60)
    cout<<"PASS"<<endl;

    else if(x<=4 && y<60)
    cout<<"FAIL"<<endl;
    .
    .
    .

    For these statements, one option is:
    Code:
    if (x <= 4)
      cout << (y >= 60 ? "PASS" : "FAIL");
    cout<<"Do you wish to continue?"<<endl;
    cout<<"(1 - Yes, 2 - No)"<<endl;
    cin>>answer;
    }
    }
    You could do other stuff, but that's a start.
    Last edited by Brown Drake; 09-05-2001 at 02:58 PM.

  7. #7
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    LOL
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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