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