954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

If statement not working

i have a problem related to the c language.

void main()
{
int marks;
clrscr();
printf("enter the marks of the student:");
scanf("%d",marks);
if(marks>=35)
{
printf("student is pass:");
}
else
{
printf("student is fail:");
}
getch();
}

but when i run this program, there is no error in the program but when i enter any input like greater than 35 marks, compiler skip the first printf statement and jump to the else statement. i enter many input such as greater and less than to 35 but compiler skip the first statement and jump at else part so what's the problem. please send me email at early because i am worried since two days aabot that; please send reply early . than you so much.

sharma89bunty
Newbie Poster
3 posts since Jun 2011
Reputation Points: 8
Solved Threads: 0
 

scanf expects a pointer:

scanf("%d", &marks);

It's a wonder that your code runs long enough to have odd behavior in the if statement.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
scanf("%d",marks)

narue is right you forgot the pointer & before marks

it should be

scanf("%d", &marks);
mtatadotcom
Newbie Poster
19 posts since Sep 2009
Reputation Points: 9
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You