English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I wrote this program, first I should say I'm an amature and I'm learning C++.
When I run this program if the input is a letter it returns you havent passed, but if the input is a number then the program halts and got hangged. whats the prob whit this program?
Im using DEV-C++ compiler


#include
#include
int main()
{
int grade;
printf("Please enter your grade: ");
scanf("%d",grade);

if(grade > 10)
{
printf("Your have passed the test.\n");
system("pause");
}
else
{
printf("You havent passed the text.\n");
system("pause");
return 0;
}
}

2007-03-31 00:50:58 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Two advices:

1) Always initialize your variables. So:

int grade; // This should be: int grade = 0;

2) Move the "return 0;" statement out of the else-statement
as follows:


else
{
printf("You havent passed the text.\n");
system("pause");
}

return 0;

2007-03-31 10:34:52 · answer #1 · answered by Silver_Sword 3 · 0 0

looks like you forgot the line "return 0;" after the system("pause"); line in your IF statement. you have it for the ELSE, but not the IF.

2007-03-31 08:40:55 · answer #2 · answered by justme 7 · 0 0

change the statement :-
scanf("%d",grade); to scanf("%d",&grade);

2007-03-31 08:53:00 · answer #3 · answered by Reverse Swing 3 · 0 0

fedest.com, questions and answers