Use of 'else if'

This is most likely very easy to solve.

I am doing a piece of coding for my university coursework in C++. I've been working on this one piece of code for at least 4 hours now and i'm stumped. Ive tried searching online but every piece of C++ information is either to complex or too simple.

When I run this code, no matter what number I input it tells me that the number represents an A grade. I just have no idea what is missing or needs to be removed in this code

int main() {


int grade;

printf("What Is the test score (Between 0 and 100)? ");
scanf("%d");

if (grade >100) {
printf("\nSorry, %d is above the grade boundry\n\n");
}
else if(grade <101 && grade >=70) {
printf("\nGrade A\n\n");
}
else if(grade <70 && grade >=60) {
printf("\nGrade B\n\n");
}
else if(grade <60 && grade >=50) {
printf("\nGrade C\n\n");
}
else if(grade <50 && grade >=40) {
printf("\nGrade D\n\n");
}
else if(grade <40 && grade >=0) {
printf("\nGrade F\n\n");
}
else if(grade < 0) {
printf("\nSorry, %d is below the grade boundaries\n\n");
}

return 0;
}
scanf() need to have 2 arguments:
1. type to read
2. variable to save read data

In your case:
%d - represents type

but you havent added variable to function.

It should look like this:
scanf("%d", &grade);

link to refference:
http://www.cplusplus.com/reference/cstdio/scanf/

gl
ohh Im sorry didnt add & - this means you give refference(address) to a variable.
Last edited on
Wow thank you so much ^.^ Worked like a charm.
Topic archived. No new replies allowed.