LOWEST SCORE DROP

I am beginning c++ trying to debug program to average the HIGHEST 4 out of 5 test scores. I CAN'T use arrays. Here is my code. It will NOT compile. PLEASE HELP :-))

#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
void getScore(int &score);
int findLowest(int, int, int, int, int);
void calcAverage(int, int, int, int, int, int);


int main ()
{
int score1, score2, score3, score4, score5, lowest;




getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);


findLowest(score1, score2, score3, score4, score5);

calcAverage(score1, score2, score3, score4, score5, lowest);


system("pause");
return 0;
}



void getScore(int &score)
{

cout << "Please enter test score (Please enter value between 1 and 100): ";
cin >> score;


while (score < 1 || score > 100)
{
cout << "ERROR: Please enter Test score values 0 to 100! ";
cin >> score;
}
}

int findLowest(int score1, int score2, int score3, int score4, int score5)
{
int lowest = score1;

{
if (score2 < lowest)
lowest = score2;
else if (score3 < lowest)
lowest = score3;
else if (score4 < lowest)
lowest = score4;
else if (score5 < lowest)
lowest = score5;
}

cout << "The lowest test score is " << lowest << endl;

return lowest;
}

void calcAverage (int score1, int score2, int score3, int score4, int score5, int lowest)

{ double average;

average = (((float)score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
//Numeric output
cout << setw(4);
cout << fixed << showpoint << setprecision(2);
cout << "The average of the 4 highest test scores entered is: " << average << endl;

}
Codes tags and error messages please.
Warning 1 warning C4700: uninitialized local variable 'lowest' used
2 IntelliSense: argument of type "int *" is incompatible with parameter of type "int"

Thanks SO MUCH for any help! I think I need call the findLowest function from inside the calcAverage function so here is my new code. Error codes are above. I can't use arrays so it's puzzling esp. since I am a newbie ;-)

#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
void getScore(int &score);
void calcAverage(int, int, int, int, int);


int main ()
{
int score1, score2, score3, score4, score5;




getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);

calcAverage(score1, score2, score3, score4, score5);


system("pause");
return 0;
}



void getScore(int &score)
{

cout << "Please enter test score (Please enter value between 1 and 100): ";
cin >> score;


while (score < 1 || score > 100)
{
cout << "ERROR: Please enter Test score values 0 to 100! ";
cin >> score;
}
}

int findLowest(int score1, int score2, int score3, int score4, int score5, int lowest)
{


lowest = score1;
if (score2 < lowest)
lowest = score2;
else if (score3 < lowest)
lowest = score3;
else if (score4 < lowest)
lowest = score4;
else if (score5 < lowest)
lowest = score5;


cout << "The lowest test score is " << lowest << endl;

return lowest;
}

void calcAverage (int score1, int score2, int score3, int score4, int score5)

{
int findLowest(int, int, int, int, int, int);
int lowest;
double average;

findLowest(score1, score2, score3, score4, score5, &lowest);

average = (((float)score1 + score2 + score3 + score4 + score5) - lowest) / 4.0;
//Numeric output
cout << setw(4);
cout << fixed << showpoint << setprecision(2);
cout << "The average of the 4 highest test scores entered is: " << average << endl;

}
Now, the code tags. Look at the "format" thingies at the right side if you don't know how to use them.
I copy pasted the program to Dev C++ IDE, and it compiled.
So, I don't know why it is not compiling on your computer.
Although, I must say, this program could have been written in a much more concise manner, without so many functions.
Much more concise way of doing the same thing.

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
30
31
32
33
34
35
36
37
#include<iostream>
#include <iomanip>

using namespace std;

int main()
{
    float score,avg=0, lowest=100;
    int i=0;
    while(i<5)
    {
        cout << "Please enter test score (Please enter value between 1 and 100): ";
        cin>>score;
        if (score>0 && score<100)
        {
           avg=avg+score;
           if (score<lowest)
           lowest=score;
           i++;
        }
        else
        {
            cout<<"ERROR: Please enter Test score values 0 to 100!"<<endl;
        }
    }
    avg=avg-lowest;
    avg=avg/4.0;  
    cout << setw(4);
    cout << fixed << showpoint << setprecision(2);
    cout<<"Average is"<<avg<<endl;
    
    return 0;
}
          
        

Topic archived. No new replies allowed.