Need help with this program! =(

Beerinator

Member
Aug 19, 2001
134
0
0
printf("\n **** Course Report for Student %i ****", id);
printf("\n\nStudent scored %i on Exam 1", ex_1);
printf("\nStudent scored %i on Exam 2", ex_2);
printf("\nStudent scored %i on Class Project", class_project);
printf("\n\nStudent scored %i points differently on Exam 2 versus Exam 1", ex_diff);
printf("\n\nStudent's exam average is %3.2f", exam_avg);
printf("\n\nStudent's average for the course is %3.2f\n", course_avg);
{
if (course_avg >= '90')
printf("\nStudent's grade in course is A");

if else (course_avg >= '80')
printf("\nStudent's grade in course is B");

if else(course_avg >= '70')
printf("\nStudent's grade in course is C");

if else(course_avg >= '60')
printf("\nStudent's grade in course is D");

else
printf("\nStudent's grade in course is F\n ");

}
return 0;
}

I can't seem to get it to print out the correct grade with the students average, I know it might seem very easy to you all but I am just starting out so please help me?
 

YaKuZa

Senior member
Aug 26, 2000
995
0
0
#1. i think the if statements should be: else if instead of if else

#2. i dont think its necessary to use '#' when doing if(course_avg >= '90'), i think if(course_avg >= 90) should work.


 

tkdkid

Senior member
Oct 13, 2000
956
0
0
You need to read up on your if statements, because you don't know how to use them.

After the last printf, you have a '{' that clearly does not belong there. The matching one at the end of the if statement block doesn't belong there either. The '{' is used to begin a code block, the '}' ends it. For example, if you had an if statement that you wanted to execute several lines of code instead of just one, you would have:
if (condition) {
statement1;
statement2;
statement3;
}
Don't just throw characters into your code if you don't know what they do. Read the book and figure it out.

Your statements should look more like:
if (course_avg>=90)
printf("\nStudent's grade in course is an A");
else if (course_avg>=80)
printf("\nStudent's grade in course is a B");
else if
....and so on..

Here's an online C reference I found while searching quickly with google
http://www.strath.ac.uk/IT/Docs/Ccourse/
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
when comparing numbers, don't use the single quote ' .. '
it will "translate" your number into ascii equivalent

eg: if (var == '65') means it's comparing var to the ascii equivalent A (which tries var == "A")
if you want number, use (var == 65) instead.

And that extra } that you have at the end ... maybe you just copy/paste the whole code block but forgot to exclude that last one ... but yah, it shouldn't be there of course.... but then again, i don't even see why you need to enclose the blocks of if's inside { ... }

finally, it's else if, not if else

-713-