probably a simple answer

This is a discussion on probably a simple answer within the C++ Programming forums, part of the General Programming Boards category; I know something is missing from this program, but I'm very new at this and can't figure it out. Could ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    48

    probably a simple answer

    I know something is missing from this program, but I'm very new at this and can't figure it out. Could anyone help?

    It should prompt the user to input 6 GPA's, but instead when you enter the first GPA it gives you the same answer six times.

    Code:
    include <iostream>
    #include <string>
    #include <cstdlib>
    using namespace std;
    
    void instructions();
    void displayGradeMsg();
    //--------------------------------------
    int main ()
    {
    // Instructions for the user.
    	instructions();
    
    	// Determines the message.
    	displayGradeMsg();
    
    	displayGradeMsg();
    
    	displayGradeMsg();
    
    	displayGradeMsg();
    
    	displayGradeMsg();
    
    	displayGradeMsg();
    
    	return 0;
    }
    //-------------------------------------
    // Instructions.
    	void instructions()
    {	
    	cout << "This program prints an appropriate transcript "
    		 << "message for any grade-point" << endl;
    	cout << "average between 0.0 and 4.0.  " 
    		 << "Each time you are prompted to enter a GPA," << endl;
    	cout << "type a value between 0.0 and 4.0 "
    		 << "and then hit the <Enter> key." << endl << endl;
    	
    }  // End instructions.
    
    	// Message determinants.
    	void displayGradeMsg()
    {
    	int gpa1;
    	  	
    
    	cout << "Please enter a grade-point average: ";
    		 
    	cin >> gpa1;
    	cout << endl;	
    	if (gpa1 >= 3.5) 
    		cout << "Highest honors for semester." << endl;
    		else if ((gpa1 >= 3.0) && (gpa1 < 3.5))	
    			cout << "Dean's list for semester." << endl;
    			else if ((gpa1 >= 2.0) && (gpa1 < 3.0))
    				cout << endl;
    				else if ((gpa1 >= 1.0) && (gpa1 < 2.0))
    					cout << "On probation for next semester." << endl;
    					else ((gpa1 >= 0.0) && (gpa1 < 1.0));
    						cout << "Failed semester--registration suspended." << endl;
    					
    	
    	return;
    }	// End message determinants.
    Last edited by sweetly; 09-30-2003 at 02:12 PM.

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    gpal is declared as an int, but you are using it as if it was a float. When you type in a float as input (like 3.7), then if gpal is an int it gets the 3 but not the .7. The next time through it sees the '.', and so it can't find an int. Maybe you should change the way gpal is declared.

    Also, remember that the last part of an if - else if - else if - else statement doesn't have an expression after the else, so this:
    Code:
        else ((gpa1 >= 0.0) && (gpa1 < 1.0));
            cout << "Failed semester--registration suspended." << endl;
    should look like this:
    Code:
        else
            cout << "Failed semester--registration suspended." << endl;
    or this:
    Code:
        else if ((gpa1 >= 0.0) && (gpa1 < 1.0))
            cout << "Failed semester--registration suspended." << endl;

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    48
    Thanks!! I got it working.
    Last edited by sweetly; 09-30-2003 at 03:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe program...
    By Kross7 in forum C++ Programming
    Replies: 12
    Last Post: 04-12-2007, 04:25 PM
  2. simple question, anyone can answer me..
    By jayhor in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2006, 05:20 AM
  3. simple 2d "putpixel" api for windows?
    By spiky in forum C Programming
    Replies: 2
    Last Post: 10-27-2005, 03:44 PM
  4. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 03:00 AM
  5. Simple simple graphics
    By triplem in forum C Programming
    Replies: 2
    Last Post: 05-19-2003, 03:52 AM

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