In this code, I have defined the five score variables before anything else, and yet, the variables always remain zero. What am I doing wrong that is preventing them from being accessed anywhere in the program?
#include <iostream>
usingnamespace std;
int score1, score2, score3, score4, score5;
void getScore(int &);
void calcAverage();
int findLowest(int);
int main ()
{
cout<<"Welcome. The intent of this program is to intake five test scores from the \n";
cout<<"user, take out the lowest score, and average them together. \n";
cout<<"When asked to input a score, please do not enter a number less than 0 or higher than 100.\n";
for (int count=1; count<=5; count++)
{
int test;
getScore(test);
switch (count)
{case 1: test=score1;
break;
case 2: test=score2;
break;
case 3: test=score3;
break;
case 4: test=score4;
break;
case 5: test=score5;}
}
calcAverage();
system ("pause");
return 0;
}
void getScore(int &sco)
{
{cout<<"Please enter a test score:";
cin>>sco ;
while (sco >100|| sco<0)
{cout<<"Your entry is invalid, please try again: ";
cin>>sco;}
}
}
void calcAverage()
{
int lowscore;
double average;
lowscore=findLowest(lowscore);
if (score1==lowscore)
{
average=(score2+score3+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<".";
}
else
{
if (score2==lowscore)
{
average=(score1+score3+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<".";
}
else
{
if (score3==lowscore)
{
average=(score2+score1+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<".";
}
else
{
if (score4==lowscore)
{
average=(score2+score3+score1+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<".";
}
else
{
average=(score2+score3+score4+score1)/4.0;
cout<<"The average of the four highest test scores is " <<average <<".";
}
}
}
}
}
int findLowest(int lowest)
{
for(int tick=0; tick<5;)
{
while (tick==0)
{ lowest=score1;
tick++; }
while (tick==1)
{ while (score2<lowest)
{lowest=score2; }
tick++;}
while (tick==2)
{ while (score3<lowest)
{lowest=score3; }
tick++;}
while (tick==3)
{ while (score4<lowest)
{lowest=score4; }
tick++;}
while (tick==4)
{ while (score5<lowest)
{lowest=score5; }
tick++;}
return lowest;}
}