Following along a C tutorial, I entered this code. When I compile and run, it aks for my age, which I enter. But it doesn't display any of the 'if' or 'else' statements. So I hit enter and the window closes. Is there a trick or am I entering the code wrong?

#include <stdio.h>

int main()        
    int age;      
    printf( "Please enter your age" );  
    scanf ("%d", &age);   
    if (age < 100) {       
    printf ("You are pretty young!\n");    
    else if (age == 100 ) {              
    printf ( "You are old \n");
else {
     printf ( "You are really old \n");    
return 0;
9 Years
Discussion Span
Last Post by Ancient Dragon

If you are using a Turbo C++ editor, then Alt+F5 will also let you see the result apart from putting getch();

Getch is nothing but a function which makes the control of the program wait till an interrupt is received from the keyboard....


abhikkumarbasu, it would really help if you'd read the threads you are responding in. He very definitely said he's using DevC++.

And I've seen other posts that you've offered the exact same advice as the post immediately before you -- and hours earlier.

We appreciate you desire to help and fully welcome it. Just try to be a little more observant so you can help people with the best advice.

add getch()

AD?!?! Really? Don't you mean getchar() ? :icon_wink:

Votes + Comments
good catch :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.