Hey guys, i'm writing this code for a grade calculator and cannot get one step further then i have right now because i don't know what to do or fix or add or anything. My question is, lets say i give the avg score of HW= A, and Proj = B and Exam= C. Given that HW= 12% of grade, Proj=28% and Exam=60%. So final equation is: (A x .12) + (B x .28) + (C x .60) = Final Grade.
My code is as follows:
#include %26lt;stdio.h%26gt;
int main()
{ int my grade; /* user's grade */
printf ("welcome.....");
printf("Enter HW1 score (out of 100"));
scanf("%d"; "HW1=a");
printf("Enter HW2 score (out of 100"));
scanf("%d"; "HW2=b");
printf("Enter HW3 score (out of 100"));
scanf("%d"; "HW3=c");
printf("Enter Proj1 score (out of 100"));
scanf("%d"; "Proj1=A");
and so on till i get all of the input questions.
then
Avg_HW=(a+b+c)/3=v1
Avg_Proj=(A+B+C+D)/4=v2
Avg_Exam=(E+F+G)/3=v3
double final_grade = (v1 * .12) + (v2 * .28) + (v3*.60);
printf("Your final Grade is, "%d" final_grade);
How do you fix all these compiling errors.?
You don't seriously expect someone to answer this
Reply:The previous answer sounded like a challenge so here it goes:
You need to focus a little more on defining the problem. As in: I'm going to enter a set of homework scores...let's call them HW1, HW2, HW2 and so on. Now don't refer to those as a, b, and c later. Same for Proj and Exam (not A, B,C and E, F, G). Notice your final equation uses A, B and C until the code is written and then it's suddenly v1,v2 and v3?
Now for the compiler errors.
'my grade' (with a space) is not a variable.
()'s need to balanced outside quotes...a ) slipped out of the quotes in the printf's
Look up the syntax for scanf...you need a reference to a declared variable the matches the type in the format.
Now that you've fixed the scanf's you need to declare all your variables in the scanf's.
Avg_HW, Avg_Proj, ... are an excellent names, but you need to declare them.
Remember the names you chose in the beginning? They should be the same as in scanf's and here. v1,v2,v3? Where did they come from?
BTW: x = y = z; is a legal statement (assigning z to x and y) but x = y+1 = z is not (y+1 is not an lvalue)
final_grade? I thought you were using 'my grade'?
The printf function takes a format string and a variable number of variables as arguments. Take a look at the format string syntax to make sure the %.. matches the variable.
Again balance ()'s and {}'s.
Clean it up. Try to compile. Then if you don't understand the compiler's complaints submit a new question with a specific issue.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment