# Help with my program??

#### Mikaila

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;

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)
{
}
else if (StudentID <=79.5 && StudentID > 64.5)
{
}
else if (StudentID <= 64.5 && StudentID > 55.5)
{
}
else
{
}

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...

#### bmitchell2407

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 )
{
}
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);

• Ian

#### Thiefcom

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 )
{
}
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