You have a lot more than just one error. I fixed all the compiler errors in the following code, but you still have some logic errors.
Errors I fixed:
Semicolons after every if and else if
Else does not have any condition that needs to go along with it
Conditions after if and else if need to be surrounded by parentheses
(
http://cplusplus.com/doc/tutorial/control/ )
char lettergrade on line 21 had extra of '{', '}', and ';'
double math on lines 5-7 does not return a double
double average needed typecasting on the integers to insure the answer returned was a double:
http://www.cplusplus.com/doc/tutorial/typecasting/
Logic errors you will still need to fix:
lettergrade function has some '<=' that might should be '>='
Suggestions:
Lines 52-57 could be replaced with
input(grade1, grade2, grade3);
double math only needs the grades passed to it (I went ahead and did this suggestion for you)
void output does not need char lg passed since it is not used in the function
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
|
#include <iostream>
using namespace std;
double math(int test1, int test2, int test3){
return double(test1+test2+test3)/3.0;
}
void output (double avg1, char lg){
cout<<"Your average is:"<< avg1;
}
void input(int &t1, int &t2, int &t3){
cout<<"Enter test1"<<endl;
cin>>t1;
cout<<"Enter test2"<<endl;
cin>>t2;
cout<<"Enter test3"<<endl;
cin>>t3;
}
char lettergrade (double average)
{
if (average>=93){
return 'A';
}
else if ((85<= average)&&(average <93)){
return 'B';
}
else if ((76<= average)&&(average <85)){
return 'C';
}
else if ((70<= average)&&(average <76)){
return 'D';
}
else if ((average<=69)&&(average<= 70)){
return 'F';
}
}
int main()
{
int grade1;
int grade2;
int grade3;
double average;
char let;
cout<<"Enter grade1:"<<endl;
cin>>grade1;
cout<<"Enter grade2:"<<endl;
cin>>grade2;
cout<<"Enter grade3:"<<endl;
cin>>grade3;
average = math(grade1, grade2, grade3);
let = lettergrade(average);
output (average, let);
return 0;
}
|