Can't figure out what is wrong.

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

using namespace std ;


string getName ();
int averageScores( int);
void printMessage (string, int);
void tallyScores ( int, int&,int&,int&);

int main()
{

const int NUMBER = 4; // number of scores for each student
char moreStudents = 'y';
string who ; //name of the student
int testAverage ;

cout << "For each student, you will be prompted for a name and "<< NUMBER << " test scores\n";
while ( moreStudents =='y' || moreStudents == 'Y')

{
who = getName () ;
testAverage = averageScores ( NUMBER);
printMessage ( who, testAverage );
cout << "\n\nMore students ? Y or N \t\t" ;
cin >> moreStudents ;
cout << endl;
cin.ignore (10, '\n');
}

system ("pause");
return 0;
} // end main
////////////////////////////////////////…
// Prompts the user to input the student's name
string getName ()
{
string name ;

cout << "\nEnter student name " ;
getline ( cin, name);
return name ;
}
////////////////////////////////////////…
// this function inputs and averages scores. Parameter howmany tells the
// number of scores to be input.

int averageScores( int howmany )
{
int sum;
int score1, score2, score3, score4 ;
double decimalAverage;
int average ; // integer average
int low;

cout << "Enter four interger scores with a space in between: " ;
cin >> score1 >> score2 >> score3 >> score4 ;

cout << "The test scores enetered are: " << score1 << " " << score2 << " " << score3 << " " << score4 << endl;
sum = score1 + score2 + score3 + score4;


if (low > score1)
{
low = score1;

}
if(low > score2)
{
low = score2;

}
if(low > score3)
{
low = score3;

}
if(low > score4)
{
low = score4;

}

cout << "The lowest score of " << low << " is dropped." << endl;
average = (sum - low) / 3;

cout << "The average with the lowest score dropped is " << average << "." << endl;
return average;
} // averageScores /

////////////////////////////////////////…
// adds to the appropriate count depeding on the score
void tallyScores ( int average, int& repeatIt,int& wow, int& passing)
{

if(average <60)
repeatIt++;

else if(average >= 95)
wow++;

else if(60 <= average < 95)
passing++;

}
//////////////////////////////////////…
// Prints out a message for the student depending on the score
void printMessage (string name, int average)
{
string message ;
if(average <60)
message = ("Gotta repeat it");

else if(average >= 95)
message = ("WOW");

else if(60 <= average < 95)
message = ("passing");

cout << "Average for " << name << " is " << average << " \t\t" << message;

} //printMessage
Last edited on
I fixed up your answers function. Since you are passing in both parameters by reference you don't need to return a double. Also you can't return 2 doubles like you are trying, only the last value would actually be returned. You need to fix your prototype above main, also you have the same prototype inside main which you don't need.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void answers(double &final_score, double &lowest)
{
  int i=0, quiz = 0;
 
  double x = 0, low = 100;
  double quizzes = 0;

  cout << "Please enter the number of quizzes: " ;
  cin >> quiz;
 
  while(i < quiz)
  {
    cout <<"Please enter the quiz scores for each quiz.";
    cin >> x; 

    if (x>0 && x<100)
    {
      if (x < low)
        low = x;

      quizzes += x;
    }

   i++;
  }

 final_score = (quizzes - low) / (quiz - 1);
 lowest = low;
}

In your averageScores() just replace the first if loop

1
2
3
4
5
if (low > score1)
{
low = score1;

}


with

low=score1.

This will do i guess from ur code
Topic archived. No new replies allowed.