Thread: Compile but cant print out answers

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    73

    trying to make more readable

    I got it finally to work....If I enter a number other than 0-100 it gives an error and asks for a new number. I was looking in my book and ran across a statement, which is what I used, but is there a better way to make it say failing or passing vs just saying failing, no passing yes...ect?


    Bryan

    Code:
    //************************************
    //This program gets 5 inputted scores 
    //from a user and determines if they 
    //have a passing or failing grade
    //************************************
    
    #include <iostream>
    
    using namespace std;
    
    const int NUM_STUDS = 5;
    
    bool passing [NUM_STUDS];
    bool failing [NUM_STUDS];
    void Initialize();
    void SetPassing(int index,const int score);
    void SetFailing(int index,const int score);
    
    
    int main()
    {
    	int index;
    	int grade;
    	int score [NUM_STUDS];
    
    	cout << "Please enter 5 test scores on a grading scale of 0-100 points. "<< endl;
    	cout << "I will tell you if the test scores are passing or failing." << endl  <<endl; 
    
    
    	for (grade =0; grade <NUM_STUDS; grade++)
    {
    	cin >> score[grade];
    
    
    if ( score[grade] < 0 )		// Check if score is too low to be a valid score:
    {
    	cout << "You entered " << score[grade] << endl;
    	cout << "It must be between 0-100." << endl;
    	grade--;
    } 
    
    
    if ( score[grade] > 100 )	// Check if score is too high to be a valid score:
    {
    	cout << "You entered " << score[grade] << endl;
    	cout << "It must be between 0-100." << endl;
    	grade--;
    } 
    }
    	Initialize();			//function call
    	for (index=0;index<NUM_STUDS;index++)
    {
    	SetPassing(index,score[index]);
    	SetFailing(index,score[index]);
    	cout<<"Score "<<score[index]<<endl;			//Printed to screen
    	cout<<"Pass  "<<(passing[index]==false ? "No" : "Yes")<<endl;
    	cout<<"Fail  "<<(failing[index]==false ? "No" : "Yes")<<endl<<endl;
    	
    }
    
    return 0;
    
    } 
    
    void Initialize()		//void statements
    
    {
    	int index;
    
    	for(index=0; index<NUM_STUDS;index++)
    	failing[index]=false;
    }
    
    void SetPassing(int index,const int score)
    
    {
    	if (score>=60)
    	passing[index]=true;
    }
    
    void SetFailing(int index,const int score)
    
    {
    	if (score<60)
    	failing[index]=true;
    }
    Last edited by romeoz; 08-02-2003 at 01:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Bypassing Print Dialog Box
    By leojose in forum Windows Programming
    Replies: 0
    Last Post: 10-13-2005, 06:44 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  4. Compile errors with overloading >> operators
    By GMHummerH1 in forum C++ Programming
    Replies: 1
    Last Post: 12-19-2004, 07:13 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM