Question asks to use if statements to test if the value entered is an A. If true print "The value of an A is 4.0" I'm struggling to get it to give the right results using char variable which the questions says to use. C programming.
int main()
{
char Grade = 'X'; // Declares a character type variable named
Grade
printf("Enter a grade\t"); // Prompts for Grade
scanf("%c", &Grade); // Inputs Grade
printf("Grade is: \t%c\n", Grade); // Prints the value of
Grade
// Part 3 - using if else statements
if(Grade>=90)
{
printf("The Value of an A is 4.0");
}
else if(Grade>=80)
{
printf("The Value of a B is 3.0");
}
else if(Grade>=70)
{
printf("The Value of C is 2.0");
}
else if(Grade>=60)
{
printf("The Value of D is 1.0");
}
else if(Grade<=60)
{
printf("The Value of F is 0.0");
}
else if(Grade==60)
{
printf("The value of <entered value of Grade> is not
defined");
}
getch();
return 0;
}
OUTPUT
Enter a grade: A
Grade is: A
The Value of an A is 4.0
EXPLANATION
I just put the char A/B/.. in the place of relational operation in the if conditions.
CODE
#include<stdio.h>
int main()
{
char Grade = 'X'; // Declares a character type variable named
Grade
printf("Enter a grade: "); // Prompts for Grade
scanf("%c", &Grade); // Inputs Grade
printf("Grade is: \t%c\n", Grade); // Prints the value of
Grade
// Part 3 - using if else statements
if(Grade == 'A')
{
printf("The Value of an A is 4.0");
}
else if(Grade == 'B')
{
printf("The Value of a B is 3.0");
}
else if(Grade == 'C')
{
printf("The Value of C is 2.0");
}
else if(Grade == 'D')
{
printf("The Value of D is 1.0");
}
else if(Grade == 'F')
{
printf("The Value of F is 0.0");
}
else
{
printf("The value of <entered value of Grade> is not
defined");
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.