help with a loop

This is a discussion on help with a loop within the C++ Programming forums, part of the General Programming Boards category; I'm stuck on a portion of my code. I'm not sure how to print a message without showing a number ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    tx
    Posts
    8

    help with a loop

    I'm stuck on a portion of my code. I'm not sure how to print a message without showing a number that determines the message.

    Instructions:
    Write a program to compute student GPA's. The program should repeatedly ask the user for a student ID number, probation status and the number of classes taken by the student this semester and then ask the user for the number of credit hours and grades for the classes. Based on this information the program should compute and output the student's semester GPA. The grades will be entered as numbers where 4.0=A, 3.0=B, 2.0=C, 1.0=D, 0.0=F. The program should also determine whether a student already on probation should be suspended or removed from probation and whether a student not already on probation should be placed on probation. At the end, the program should output a count of the total number of students, the number now on probation and the number now suspended.
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
        
        int studentid, probationstat, numclasses, credithours, totalhours=0;
        double gpa, classgrade, semestergpa, totalgrade=0;
        
        
        
        cout<<"-------------------------------------------------- \n";
        cout <<"Enter the student ID: ";
        cin >> studentid;
        
        while (studentid != -1)
        {
        cout <<"Enter probation status: ";
        cin >> probationstat;
        cout <<"Enter number of classes taken by student: ";
        cin >> numclasses;
            while (numclasses > 0)
                  {           
                  cout <<"Enter credit hours and grade for a class: ";
                  numclasses=numclasses-1;
                  cin>>credithours>>classgrade;
                  }
                  
                  
                  gpa=credithours*classgrade;
                  totalgrade=totalgrade+classgrade;
                  totalhours=totalhours+credithours;
                  semestergpa=gpa/totalhours;
                  
                   cout.setf(ios::fixed | ios::showpoint); // display 4 decimals for GPA
                   cout.precision(4);
    
        cout <<"Semester GPA: " << semestergpa <<"\n";
        cout <<"New Status: " << probationstat <<"\n";
        if ((probationstat == 1) && (gpa < 2.0))
       {
       cout <<"SUSPENDED"<<endl;
       } 
    else if ((probationstat == 1) && (gpa > 2.5) && (credithours > 6))
       {
       cout <<"NOT ON PROBATION"<<endl;
       }
    else if ((probationstat == 1) && (gpa > 2.5) && (credithours < 6))
       {
       cout <<"ON PROBATION"<<endl;
       }
    else if ((probationstat == 1) && (gpa > 2.0) && (gpa < 2.5))
       {
       cout<<"ON PROBATION"<<endl;
       }
    else if ((probationstat == 2) && (gpa < 2.0))
       {
       cout<<"ON PROBATION"<<endl;
       }
    else if ((probationstat == 2) && ( gpa > 2.0))
      {
      cout<<"NOT ON PROBATION"<<endl;
      }
        cout <<"------------------------------------------------- \n";
        cout <<"Enter the student ID: ";
        cin >> studentid;
        }    
    
    system("PAUSE");
    return 0;
    }
    Whenver I run this, the output of the student's status looks like this if the condition is met:

    Code:
    New Status: 1  On Probation
    I'm wondering how can I get it just to say "On Probation" or any other possible message without displaying the number?

    P.S. I know the math isn't calculating perfectly. That's something I can work out.
    Last edited by letsgetaway; 09-21-2006 at 01:12 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    >> cout <<"New Status: " << probationstat <<"\n";
    Maybe I don't understand, but doesn't that line output the text you don't want? Perhaps removing that line will solve your problem?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    tx
    Posts
    8
    Here's the sample I/O the progam is supposed to show.

    Code:
    -----------------------------------------------------
    Enter student ID: 1207
    Enter probation status: 2
    Enter number of classes taken by student:  3
    Enter credit hours and grade for a class:  3  0.0  
    Enter credit hours and grade for a class:  3  1.0   
    Enter credit hours and grade for a class:  3  2.0   
    SemesterGPA = 1.0000   
    New Status = ON-PROBATION
    -----------------------------------------------------
    Somehow I am able to get the message to print under "New Status" but I don't know how to get it without showing the number entered for the probation status.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Do you see where in the code the number is being output?

  5. #5
    Registered User
    Join Date
    Sep 2006
    Location
    tx
    Posts
    8
    Thanks for trying to help. Someone was able to help me. It's the simple errors that leave me guessing where I went wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

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