September 15th, 2012, 12:48 PM
Really simple program
I am trying to make a really simple program that calculates your grade based on percentages that certain things are worth. im pretty much brand new to c programming and just trying to goof around with my own ideas inbetween class projects. heres my code
and i get this error when compiling
float test; // based on tests being worth 30% of grade
float final; // based on tests being worth 20% of grade
float labs; // based on tests being worth 50% of grade
printf("Please enter your average test grade\n");
printf("Please enter your final test grade\n");
printf("please enter your average lab grade\n");
grade = (test * .30) + (final * .20) + (labs * .50);
printf("your grade for this class is: %0.2f", grade);
In function ‘main’:
c-projects/personal/grade_calc.c:19:1: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double’ [-Wformat]
so the error is with the %f thats supposed to be assigned to labs but im not really sure why thats an error.
any help would be greatly appreciated, i know its probably something silly that im just not seeing but have been looking at this for over an hour now and cant put my finger on it.
edit for error message because i was testing out %d instead of %f and posted the old message from test.
September 15th, 2012, 01:01 PM
found what was wrong, sorry to waste anyones time, was missing an & lol i knew it was a stupid mistake just had to take my eyes off it for a min to see
September 16th, 2012, 11:27 PM
you should give & to labs i.e scanf("%f", &labs);