puts("Enter a student Grade");
scanf("%f", &Grade);
if (Grade <= 59.9) {
printf("The Grade is F ", Grade);
}
else if (Grade >= 60 && Grade <= 69.9) {
printf("The Grade is D", Grade);
}
else if (Grade >= 70 && Grade <= 79.9) {
printf("The Grade is C", Grade);
}
else if (Grade >= 80 && Grade <= 89.9) {
printf("The Grade is B", Grade);
}
else if (Grade >= 90 && Grade <= 100) {
printf("The Grade is A", Grade);
}
return 0;
}
am getting two errors one is illegal else without matching if on line 24 and Error C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNING on line 8 can someone see what is the problem that i have here please
It seems Error C4996 is Microsoft related - if you changed compiler, it wouldn’t give you that error.
To avoid that error, someone suggests using the following instructions before loading your header:
I couldn’t find the cause of your “else without if" error, because my compiler didn’t complain about anything, as well as goldenchicken’s one. Anyway also the following code compiles without errors or warnings, but I can’t know if it’s what you aimed to do:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif // _MSC_VER
#include <stdio.h>
int main()
{
double Grade;
puts("Enter a student Grade: ");
scanf("%lf", &Grade);
if (Grade <= 59.9) {
printf("The Grade %d means a F", int(Grade));
}
elseif (Grade >= 60 && Grade <= 69.9) {
printf("The Grade %d means a D", int(Grade));
}
elseif (Grade >= 70 && Grade <= 79.9) {
printf("The Grade %d means a C", int(Grade));
}
elseif (Grade >= 80 && Grade <= 89.9) {
printf("The Grade %d means a B", int(Grade));
}
elseif (Grade >= 90 && Grade <= 100) {
printf("The Grade %d means a A", int(Grade));
}
}
However in C++ you shouldn’t use headers like <stdio.h>, but their equivalent like <cstdio>.
Are you programming in C, perhaps? Maybe you want to post your question in a C forum.
warning C4996: 'scanf': This function or variable may be unsafe.
It's not an error, but a warning. It can be ignored or disabled .
However the other warnings should be fixed. printf("The Grade is F ", Grade);
warning C4474: 'printf' : too many arguments passed for format string
1 2 3 4 5
char A;
char B;
char C;
char D;
char F;
warning C4101: 'A': unreferenced local variable
warning C4101: 'B': unreferenced local variable
warning C4101: 'C': unreferenced local variable
warning C4101: 'D': unreferenced local variable
warning C4101: 'F': unreferenced local variable