So first of all, here is my code :
#include <stdio.h>
double total(double assignment, double mid, double final){
double totalScore;
totalScore = (assignment * 0.2) + (mid * 0.3) + (final * 0.5);
return totalScore;
}
char grade(char Z, char X, char Y, char P){
char gradeAchieved;
if (total(assignment, mid, final) >= 80 )`{
gradeAchieved = Z;
}
else if ((total(assignment, mid, final) >= 70) && (total(assignment, mid, final) < 80) ){
gradeAchieved = X;
}
else if ((total(assignment, mid, final) >= 60) && (total(assignment, mid, final) < 70) ){
gradeAchieved = Y;
}
else if (total(assignment, mid, final) < 60){
gradeAchieved = P;
}
return gradeAchieved;
}
int main()
{
double x;
double y;
double z;
char A = 'A';
char B = 'B';
char C = 'C';
char D = 'D';
printf("Input your assignment score: ");
scanf("%lf", &x);
printf("Input your midtest score: ");
scanf("%lf", &y);
printf("Input your final test score: ");
scanf("%lf", &z);
printf("Your total score is: %lf", total(x, y, z));
printf("Your grade is: %c", grade(A, B, C, D));
return 0;
}
in my code, its supposed that when I run it, you will get a prompt to input your assignment, mid, and final grade. Then it will calculate your final score and decides whether you get an A, B, C, or D. But it seems that every time i tried to run it, i got this error message:
main.c: In function ‘grade’:
main.c:17:15: error: ‘assignment’ undeclared (first use in this function)
if (total(assignment, mid, final) >= 80 ){
^~~~~~~~~~
main.c:17:15: note: each undeclared identifier is reported only once for each function it appears in
main.c:17:27: error: ‘mid’ undeclared (first use in this function)
if (total(assignment, mid, final) >= 80 ){
^~~
main.c:17:32: error: ‘final’ undeclared (first use in this function)
if (total(assignment, mid, final) >= 80 ){
^~~~~
And I don't really know how to solve it. So could anybody help me? And sorry for my bad english
The reason for the three error messages is that you haven't declared any variables named assignment
, mid
, and/or final
in your function grade()
. You could move the four char
variables into the grade()
function and change the function parameters to match total()
and your code should run.
char grade(double assignment, double mid, double final){
char A = 'A';
char B = 'B';
char C = 'C';
char D = 'D';
char gradeAchieved;
if (total(assignment, mid, final) >= 80 ) {
gradeAchieved = A;
}
else if ((total(assignment, mid, final) >= 70) && (total(assignment, mid, final) < 80) ){
gradeAchieved = B;
}
else if ((total(assignment, mid, final) >= 60) && (total(assignment, mid, final) < 70) ){
gradeAchieved = C;
}
else if (total(assignment, mid, final) < 60){
gradeAchieved = D;
}
return gradeAchieved;
}
int main()
{
double x;
double y;
double z;
printf("Input your assignment score: ");
scanf("%lf", &x);
printf("Input your midtest score: ");
scanf("%lf", &y);
printf("Input your final test score: ");
scanf("%lf", &z);
printf("Your total score is: %lf", total(x, y, z));
printf("Your grade is: %c", grade(x, y, z));
return 0;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments