Can someone help me with my code
for this code:
#include <iostream>
using namespace std;
int main()
{
int score[5], t, x;
int low, avg;
char let;
cout<<"Enter 5 test grades: \n";
for(t=0; t<=4; t++) {
cin>>score[t];
}
for(x=0,t=0;t<5 && x<5;t++) {
for(;;x++) {
if(x==5) low=score[t] break;
else if(score[t]>score[x]) break;
}
}
avg=(score[0]+score[1]+score[2]+score[3]+score[4]-score[t])/4;
if(avg>90) let= ''A'';
else if(avg>79 && avg<90) let= ''B'';
else if(avg>74 && avg<80) let= ''C'';
else if(avg>69 && avg<75) let= ''D'';
else let=''F'';
cout<<"The lowest test grade is "<<score[t]<<"\n";
cout<<"The numerical average of the other four grades is "<<avg<<"\n";
cout<<"The letter average of the other four grades is "<<let;
return 0;
}
I get the following errors in dev-c++:
[warning]in function ''int main()'':
line 16-parse error before ''break''
does anyone know why i am getting these errors?
quote:Original post by Penguinzchaseme
{
if(x==5) low=score[t]*here* break; <------
else
you''re missing there a ;
that should do it
To be considered a genius you just have to say what everybody knows in a way very few understand
Change the line where says...
if(x==5) low=score[t] break;
and there put...
if(x==5) {low=score[t]; break;}
I hope that this was the problem.
if(x==5) low=score[t] break;
and there put...
if(x==5) {low=score[t]; break;}
I hope that this was the problem.
I''m anonymous because the moderators have fettered my name, . Your code allocates space for 6 grades, ie score[5],ie score[5]={0,1,2,3,4,5}...it should be score[4]; gotta remember the 0 is part of the array index!
quote:Original post by Anonymous Poster
I''m anonymous because the moderators have fettered my name, . Your code allocates space for 6 grades, ie score[5],ie score[5]={0,1,2,3,4,5}...it should be score[4]; gotta remember the 0 is part of the array index!
You got it wrong; score[5] allocates space for 5 variables from 0..4.
"George W. Bush Geography Simplification Initiative"
More info on George W. Bush
My Homepage (C++ SDL OpenGL Game Programming)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement