Can someone help me to explain what is wrong in my c code?

Smarkite

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

RTT

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.

edited at
0

Comments

0 comments
Login to comment

Related

what is wrong in my code? Can someone help me

Can someone help me find what is wrong with my code?

Can someone tell me whats wrong with my code and try to explain it?

Can someone explain what went wrong with my code?

Can someone help me figure out what's wrong with my code?. It translates RNA sequences into proteins

Can someone please help me what is wrong with this code

Can someone explain to me what is wrong with the logic

Could someone explain to me what I'm doing wrong in this Python Code and help me figure it out?

Can someone explain what is wrong with my approach?

my code seems perfect but showing wrong output. can someone help me what wrong am i doing here?

Can someone please tell me what is wrong with my code?

Can someone explain to me what this code does?

Can someone explain to me what this code is doing?

Can someone explain what's wrong with my code and how does my teacher's code work?

Can someone help me with my code problem?

Please could someone help me explain what this javascript code means?

Can anyone help me find what is wrong with my code?

Can someone help me explain this code that is converting decimal fractions into a binary?

Can someone explain what is wrong with my code that is trying to compare 2 arrays?

Can someone help me to figure out what's wrong in my implementation of merge sort?

Can Someone help me point out where my code is going wrong with the output?

Can someone please explain what's wrong with this code?

Can Someone Help Me To Find What Is Wrong With This Java Programming

Can someone help me what's wrong with this bubble sort?

Can someone explain to me what the code below is doing?

Can someone explain to me what does 'as never' do in this piece of code?

Can someone explain to me in what language this API code is written in?

Can someone please explain to me what is happening in this line of code?

Can someone explain me what this line of ruby code does?