Issue
This Content is from Stack Overflow. Question asked by Tejas18
# include<stdio.h>
int main() {
int marks;
printf("enter marks: ");
scanf("enter marks: %d ", &marks);
if(marks > 30)
{
printf("passed");
}
else
{
printf("not");
}
return 0;
}
The criteria that I put doesn’t help in the output, even if enter marks as 14, then too it displays passed. I am a beginner, so please help.
Solution
printf("enter marks: ");
scanf("enter marks: %d ", &marks);
Is not correct.
You do not put a "prompt" in scanf
. Only the value you want to read.
It should be:
scanf("%d", &marks); // Prompt was already done with printf on prior line
This Question was asked in StackOverflow by Tejas18 and Answered by abelenky It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.