Design and implement an algorithm to solve this problem; your solution should use user – defined functions. Do not access global variables. Use parameters! (Suggestions: int function to determine lowest of two numbers, void function to print the message) Use function prototypes; the source code for functions should follow the source code for the main function.

Input a student’s full name and four integer scores (you need getline for the name)
Average the scores – drop the lowest grade; round to the nearest integer
Formula to drop the low grade: average = (sum of all 4 scores -low score) / 3
Print out a message that includes the student name, average, and one of the following:
Exceptional for averages >= 95
Passing for 60 <= averages <95
Gotta repeat it for averages < 60.
After your program works correctly for one student, add a loop so the user can process any number of students.


What I have so far.... Please get it to run! I'm stumped!

#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

string GetName();
int GetScore();
int LowScore(int, int, int, int);
int GetAverage();
double ComputeAverage ( int, int, int, int );
void printResult (string, double);

int main(int argc, char *argv[])
{
    
    int s1, s2, s3, s4;
    int low, score;
    string FullName;
    char name;
    char done = 'n',
         g = 1;
    double Average;
    cin.get();
    
    while(1)
    {
    FullName = GetName();
    s1= GetScore();
    s2= GetScore();
    s3= GetScore();
    s4= GetScore();
    
    Average = ComputeAverage (s1, s2, s3, s4);
    printResult( FullName, Average);
    FullName.clear();
    
    cout << "Would you like to continue?\n(Y/N)" <<endl;
    cin>> done;


    system("PAUSE");
    return EXIT_SUCCESS;
}

string GetName();
{
char name;
 cout<< "Please enter your student's full name.\n" << endl;
 //cin.ignore (cin.rdbuf()->in avail());
 getline (cin, FullName);
 cout<< endl;
 return (name);
 }
 
int GetScore();
{
    int score;
    cout<< "Please enter score. \n";
    cin >> score;
    cout<< endl;
    return (score);

}


int LowScore(int s1, int s2, int s3, int s4);
{
    int s1, s2, s3, s4;
    
    if (s1 < s2 && s1 < s3 && s1 < s4)
    {return s1;}
    
     else if (s3 < s2 && s3 < s1 && s3 < s4)
    {return s3;}
    
     else if (s2 < s1 && s2 < s3 && s2 < s4)
    {return s2;}
    
     if (s4 < s2 && s4 < s3 && s4 < s1)
    {return s4;}
    return (low);
    
}
 
 double ComputeAverage();
 {
     int low;
     double Average;
     low = LowScore(s1, s2, s3, s4);
     Average = static_cast<double>((s1 + s2 + s3 + s4 - low)/3.0 +.5); 
    
     return (Average);
     }
     
     void printResults(string FullName, double Average)
     {cout<< "Student's Name: " << name << endl;
     cout<< "The average score is: " << Average <<endl; 
      if(Average >= 95)
    { cout << "Exceptional" << endl;
    }
    else if (Average >= 60 && Average < 95)
    {cout << "Passing" << endl;}
    else
    cout << "Gotta repeat it" <<endl;
}

Recommended Answers

All 6 Replies

>What I have so far.... Please get it to run! I'm stumped!

Bjarne Stroustrup's advice - If you can think of ‘‘it’’ as a separate idea, make it a class. The key to writing good programs is to design classes so that each cleanly represents a single concept.

Please read the rules before posting again, in particular the 'keep it organized' one - subject titles such as 'help urgent' are not allowed. If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.

>What I have so far.... Please get it to run! I'm stumped!

Bjarne Stroustrup's advice - If you can think of ‘‘it’’ as a separate idea, make it a class. The key to writing good programs is to design classes so that each cleanly represents a single concept.

Please read the rules before posting again, in particular the 'keep it organized' one - subject titles such as 'help urgent' are not allowed. If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.

I'm quite sorry. I will try my best from now on to take my time posting. and keep this organized.

So, i guess I'm just having some trouble getting my return statement to return a stated Average. and being able to achieve all needed calculations stated in the prompt.

Look at line 70. Notice anything particular about it? Also line 98 is wrong. Your instructions say to calculate the average of the 3 highest scores to the nearest integer. Does a double qualify as an integer? These are some things for you to look at. Remember it is better to start small and debug constantly then to write the whole program and hope it works.

oh thank you so much for picking up on the 98. but im new to C++, as you can probably tell, and I don't see the mistake in line 70, if 18 is basically the the same statement.

You're attempting to re-declare the parameters that you have already sent to the function. The line is completely redundant and not necessary.

What Fbody said. The variables were already declared in the function declaration so when you re defined them the became garbage and were giving you a incorrect answer. Also your formula for calculating the average is flawed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.