CSCI 131 Techniques of Programming--Spring 2014

    Home | | Schedule | | Assignments | | Lectures | | Resources

    Solution to Lab 3 grades.cc

    //**********************************************************************
    // grades.cc
    //     Author:  Royden/King
    //     Date:    February 10, 2014
    //     Class:   CSCI 131
    //     Purpose: This program determines whether a student is passing
    //              based on the average of his or her three grades
    //     Input :  (from standard input) The three grades, as integers
    //     Output:  (to standard output) The student's average
    //**********************************************************************
    
    #include <iostream>
    
    using namespace std;
    
    int main( void )
    {
        int   test1;
        int   test2; 
        int   test3;         // three test grades for a student
        float average;       // average of a student's three grades
        
        //  Prompt the user for the input
        
        cout << "Enter 3 grades for a student: ";
        cin >> test1 >> test2 >> test3;
        cout << endl;
        
        //  Determine if the data is valid and calculate the average if it is
        
        if ((test1 < 0) || (test2 < 0) || (test3 < 0)) {
            cout << "Invalid data." << endl;
            return 1;
        }
        else {
            average = (test1 + test2 + test3) / 3;
            cout << "Student average = " << average << endl;
        	
        	//  Print a message saying that the student is passing or failing
        
            if (average >= 60.0) {
                cout << "Student is passing";
                if (average < 70.0)
                    cout << ", but marginal";
                cout << "." << endl;
            } // if
    
            else
                cout << "Student is failing!" << endl;
        } //else    
        return 0;
    } // main
    
    

    Home | | Schedule | | Assignments | | Lectures | | Resources



    CSCI 131: Techniques of Programming
    Last Modified: February 10, 2014
    Page Expires: February 10, 2015