Help with my program??

Joined
Sep 30, 2016
Messages
1
Reaction score
0
Hi,

I am having trouble with just one detail of my code and can't figure out how to fix it... any help would be greatly appreciated!


In C:

#include <stdio.h>
#pragma warning (disable: 4996);

int StudentID = 0;
float Percentage = 0.0;
char Grade = 'a';

int main()
{
printf("Enter the student's id: ");
scanf(" %d" , &StudentID);

if (StudentID > 9999999999 || StudentID < 0)
{
printf("Invalid student number program terminating");
return 1;
}
else
{
printf("Enter the student's percentage score: ");
scanf(" %1.1f" , &Percentage);




if (Percentage >= 0 && Percentage <= 100)

{
if (StudentID <= 100 && StudentID > 79.5)
{
Grade = 'A';
}
else if (StudentID <=79.5 && StudentID > 64.5)
{
Grade = 'B';
}
else if (StudentID <= 64.5 && StudentID > 55.5)
{
Grade = 'C';
}
else
{
Grade = 'F';
}

printf("The student with id %d" , StudentID);
printf(" scored %1.1f" , Percentage);
printf("%% on the exam\nThe student will recieve a %c" , Grade);
}
}

return 0;
}

The output is (with the user input italicized):

Enter the student's id: 123456
Enter the student's percentage score: 89
The student with id 123456 scored 0.0% on the exam
The student will receive a F

I don't understand why it is keeping the percentage as 0.0...
 
Joined
Oct 10, 2016
Messages
1
Reaction score
1
Hi,

Your problem is in your if statement at the bottom of the code. You're assigning a grade (A, B, C, F) based on the StudentID when you need to check the Percentage instead.

like:

if ( Percentage <= 100 && Percentage > 79.5 )
{
Grade = 'A';
}
etc.

Also, I think you're getting 0.0 for percentage because you're constraining the percentage in the scanf() line. Try and see if this works:

scanf("%f", &Percentage);
 
Joined
Jun 1, 2017
Messages
55
Reaction score
7
Hi,

Your problem is in your if statement at the bottom of the code. You're assigning a grade (A, B, C, F) based on the StudentID when you need to check the Percentage instead.

like:

if ( Percentage <= 100 && Percentage > 79.5 )
{
Grade = 'A';
}
etc.

Also, I think you're getting 0.0 for percentage because you're constraining the percentage in the scanf() line. Try and see if this works:

scanf("%f", &Percentage);
Yea thats right
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top