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 %26lt;stdio.h%26gt;
#include %26lt;windows.h%26gt;
int main()
{
int grade;
printf("Please enter your grade: ");
scanf("%d",grade);
if(grade %26gt; 10)
{
printf("Your have passed the test.\n");
system("pause");
}
else
{
printf("You havent passed the text.\n");
system("pause");
return 0;
}
}
C++ Problem, please help...?
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;
Reply: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.
Reply:change the statement :-
scanf("%d",grade); to scanf("%d",%26amp;grade);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment