Home > Back-end >  Why is my 'char' variable not printing an output?
Why is my 'char' variable not printing an output?

Time:09-19

My task is to write a program with five functions. All the functions are working just fine, the only problem is that my char, Gr, is not printing in the output.

This is the code:

#include <stdio.h>
void fnInput (long int*, float*, float*, float*);
float fnSumMarks (float, float, float, float*);
float fnComputeGrade (float,char*); 
void fnPrintAll (long int, float, char);
void fnPrintMatrixGrade (long int, char);

void fnInput (long int*Mx, float*T1, float*T2, float*Tf)
{
printf("Enter your matrix number:");
scanf("%ld", Mx);
printf("\nEnter your marks for Test 1(/25):");
scanf("%f", T1);
printf("\nEnter your marks for Test 2(/25):");
scanf("%f", T2);
printf("\nEnter your marks for Final Test(/50):");
scanf("%f", Tf);
}
float fnSumMarks(float T1, float T2, float Tf, float*Ts)
{
    *Ts = T1   T2   Tf;
    return(*Ts); 
}
float fnComputeGrade (float Ts, char*Gr) 
{
    if (Ts >= 80)
    return (*Gr == 'A');
    else if (Ts >= 65)
    return (*Gr == 'B');
    else if (Ts >= 50)
    return (*Gr == 'C');
    else if (Ts >= 40)
    return (*Gr == 'D');
    else if (Ts >= 25)
    return (*Gr == 'E');
    else
    return (*Gr == 'F');
}
void fnPrintAll(long int Mx, float Ts, char Gr)
{
printf("\nTotal marks for %ld is %f and the grade is %c",Mx,Ts,Gr);
}
void fnPrintMatrixGrade(long int Mx, char Gr)
{
printf("\nMatrix No.: %ld\nGrade: %c",Mx,Gr);
}
int main(void)
{
float T1, T2, Tf, Ts;
long int Mx;
char Gr;
fnInput(&Mx, &T1, &T2, &Tf);
fnSumMarks(T1, T2, Tf, &Ts);
fnComputeGrade(Ts, &Gr);
fnPrintAll(Mx, Ts, **Gr**);
fnPrintMatrixGrade (Mx, **Gr**);
return 0;
}

This is the output:

Enter your matrix number:222123223
Enter your marks for Test 1(/25):22
Enter your marks for Test 2(/25):23
Enter your marks for Final Test(/50):46
Total marks for 222123223 is 91.000000 and the grade is 
Matrix No.: 222123223
Grade:

CodePudding user response:

You should return the result as a char:

char fnComputeGrade (float Ts)
{
    if (Ts >= 80) return 'A';
    else if (Ts >= 65) return 'B';
    else if (Ts >= 50) return 'C';
    else if (Ts >= 40) return 'D';
    else if (Ts >= 25) return 'E';
    else return 'F';
}

And then assign it to your variable Gr:

char Gr=fnComputeGrade(Ts);
  •  Tags:  
  • c
  • Related