I can't get this code to compile. There are several global variables that I want to use. I can't get the variable "count" to be recognized, thought it seems that the others are, I only say that because there aren't any errors being reported by the compiler for them. I also am having trouble getting the return function to work correctly.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <iostream>
using namespace std;
int score1, score2, score3, score4, score5, count;
void getScore(int &, int &, int &, int &, 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 (count=1; count<=5; count++)
{
getScore(score1, score2, score3, score4, score5);
}
calcAverage();
system ("pause");
return 0;
}
void getScore(int &sc1,int &sc2,int &sc3,int &sc4,int &sc5)
{
int test;
cout<<"Please enter test score " <<count <<":\n";
cin>>test ;
while (test >100|| test< 0)
{cout<<"Your entry is invalid, please try again: ";
cin>>test;
switch (count)
{case 1: test=sc1;
break;
case 2: test=sc2;
break;
case 3: test=sc3;
break;
case 4: test=sc4;
break;
case 5: test=sc5;}
}
calcAverage();
{
int lowscore;
double average;
lowscore=findlowest(lowest);
if (score1==lowest)
{
average=(score2+score3+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<"."
}
else
{
if (score2==lowest)
{
average=(score1+score3+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<"."
}
else
{
if (score3==lowest)
{
average=(score2+score1+score4+score5)/4.0;
cout<<"The average of the four highest test scores is " <<average <<"."
}
else
{
if (score4==lowest)
{
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;
}
|
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\Projects\Untitled1.cpp" -o "C:\Dev-Cpp\Projects\Untitled1.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
C:\Dev-Cpp\Projects\Untitled1.cpp: In function `int main()':
C:\Dev-Cpp\Projects\Untitled1.cpp:18: error: `count' undeclared (first use this function)
C:\Dev-Cpp\Projects\Untitled1.cpp:18: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Dev-Cpp\Projects\Untitled1.cpp: In function `void getScore(int&, int&, int&, int&, int&)':
C:\Dev-Cpp\Projects\Untitled1.cpp:33: error: `count' undeclared (first use this function)
C:\Dev-Cpp\Projects\Untitled1.cpp:58: error: `lowest' undeclared (first use this function)
C:\Dev-Cpp\Projects\Untitled1.cpp:58: error: `findlowest' undeclared (first use this function)
C:\Dev-Cpp\Projects\Untitled1.cpp:67: error: expected `;' before '}' token
C:\Dev-Cpp\Projects\Untitled1.cpp:74: error: expected `;' before '}' token
C:\Dev-Cpp\Projects\Untitled1.cpp:81: error: expected `;' before '}' token
C:\Dev-Cpp\Projects\Untitled1.cpp:88: error: expected `;' before '}' token
C:\Dev-Cpp\Projects\Untitled1.cpp:93: error: expected `;' before '}' token
C:\Dev-Cpp\Projects\Untitled1.cpp:111: error: a function-definition is not allowed here before '{' token
C:\Dev-Cpp\Projects\Untitled1.cpp:111: error: expected `,' or `;' before '{' token
C:\Dev-Cpp\Projects\Untitled1.cpp:139: error: expected `}' at end of input
Execution terminated