Help!!

This is a discussion on Help!! within the C++ Programming forums, part of the General Programming Boards category; I have two assigments due in the morning and I left my book in the computer lab and it's locked ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    6

    Help!!

    I have two assigments due in the morning and I left my book in the computer lab and it's locked up. I think I got the first one done, but the second one I don't know.
    Here is the problem.

    make a program to allow a student to obtain hes GPA. each class may vary on number of credit hours. therefor there will be 2 inputs, grade and credit hours. promp the student to use a numeric value for thye grade 4 for A, 3 for B and so on. A student may take one or several classes. ID must be an input value. No need to echo input except for ID, but should display the credit hours that the student has earned as well as the GPA.

    I did this when I had my book, but I think it is way off. this is our second program and we only know very simple steps. Any help would be great.

    #include <iostream>
    #include <cctype>
    using std::cin;
    using std::cout;

    int main()
    {
    int id, mark = 0;
    char yesno = 'y';

    do {
    do {
    cout<<"Please enter ID:";
    cout<<"Please enter grade: ";
    cin>>grade;
    cout<<"Please enter credit hours: ";
    cin>>mark;
    } while ( (mark < 0) && (mark > 100) )


    if (mark>=4)
    cout<<"Student "<<id<<" got a grade A";
    else if (mark>=3)
    cout<<"Student "<<id<< " got a grade B";
    else if (mark>=3)
    cout<<"Student "<<id<< " got a grade C";
    else if (mark>=2)
    cout<<"Student "<<id<< " got a grade D";
    //else if (mark<=2) //
    else
    cout<<"Student "<<id<< " got a grade F";

    cout<<"Again?: ";
    cin>>yesno;
    } while (toupper(yesno)!='N');
    cout<<
    return 0
    Last edited by oubeta; 10-02-2002 at 10:04 PM.

  2. #2
    Wynder
    Guest
    To start, it looks like ID is never used, so when you try to run it, you'll come up with garbage when you try to cout the students ID.

    Second, take a peek at your while, you probably meant ( (mark < 0) && (mark > 100) )

    But if the assignment is to get the GPA, they probably want you to keep track of the total of points(marks), then divide by the number of marks entered.

    (ie, 3+4+2+3 = 12, 12/4 = 3, which would be their GPA).

    Wynder

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    6
    Ok let me stare at it a while. I so lost without my book. I a "newbie" but I enjoy doing it,,,i think.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    6
    I think this is all I can do without my book. How wrong is it?
    I'm really lost..
    Any help with it would be great

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    6
    Code:
    #include <iostream>
    #include <cctype>
    using std::cin;
    using std::cout;
    
    int main()
    {
      int id, mark = 0;
     
    
      do {
        do {
          cout<<"Please enter ID:"; 	
          cout<<"Please enter grade: ";
          cin>>grade;
          cout<<"Please enter credit hours: ";
          cin>>mark;
        } while ( mark < 0 && 100 > mark );
    
        if (mark>=4)
          cout<<"Student "<<id<<" got a grade A";
        else if (mark>=3)
          cout<<"Student "<<id<< " got a grade B";
        else if (mark>=3)
          cout<<"Student "<<id<< " got a grade C";
        else if (mark>=2)
          cout<<"Student "<<id<< " got a grade D";
        //else if (mark<=2)  // 
        else
            cout<<"Student "<<id<< " got a grade F";
    
        cout<<"Again?: ";
        
      }
    How's this

    &#91;code]&#91;/code]tagged by Salem

  6. #6
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    From what i can see, you haven't received an input for the ID, and i think you need to put this in.

    Also,
    Code:
    while ( mark < 0 && 100 > mark );
    should be
    Code:
    while ( mark < 0 || mark > 100 );
    if you are repeating it until you get a correct code.
    IDE: Dev C++ 5
    Lib: Allegro
    OS: Windows 2000

Popular pages Recent additions subscribe to a feed

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