I am new in C++ help me

When I run the program, it tells me to enter the gpa, but when I enter the gpa, it does not put you have failed, you have passed.

#include <stdio.h>

int main ()
{
int gpa;
printf("Enter your gpa: ");
scanf("%f",&gpa);
if(gpa>=5.0&&gpa<=3.01){
printf("You have failed.");
}else
if(gpa>=3.0&&gpa<=1.76){
printf("You have passed.");
}else
if(gpa>=1.75&&gpa<=1.51){
printf("You are a Dean lister for this semester!");
}else
if(gpa>=1.50&&gpa<=1.0){
printf("You are a President lister for this semester!");
}

}
Please use code tags when posting code.
https://www.cplusplus.com/articles/jEywvCM9/

And what you posted is C, not C++.
1
2
int gpa;
scanf("%f",&gpa);


Format specifier "%f" expects a pointer to a float* where result will be stored, not an int* pointer!

Use format specifier "%d" to read an int. Or, if you actually want to read a "real" number, use a float variable.

Please see here for details:
https://www.cplusplus.com/reference/cstdio/scanf/
Last edited on
Topic archived. No new replies allowed.