#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 {
                            if(age>100)
                        {
                            printf("You are really old\n");
                            }
                        }
          }
          getchar();
          return 0;
}                        

the program just flashes wen i click run and doesnt stay on screen. help please..

Edited 3 Years Ago by Dani: Formatting fixed

I compiled it, and ran it. It works fine for all three outputs. It works also without the 'getchar();' at the end. Compiler issue?

I compiled it, and ran it. It works fine for all three outputs. It works also without the 'getchar();' at the end. Compiler issue?

maybe its a compiler issue. becuz im using a 32bit version on a 64bit processor so its saying it might not work well on start up.

is there a 64bit verion anyway?

What are you using as an IDE? Always best to get the right architecture..

remember im a newbie plaease break that down for me ok

maybe its a compiler issue.

It is a normal result of stream I/O in C. The problem is that there is still a character left in the stream after calling scanf(), and getchar() eats it without blocking. The IDE you are using probably closes the window after main() returns, so the window goes away. Calling getchar() is supposed to stop that, but it only works if the stream is clean when getchar() is called.

You can clean the stream with repeated calls to getchar() until '\n' is found. This will produce the right behavior if the stream is not clean, and it will only require an extra [Enter] to be typed if the stream is already clean:

#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
        {
            if(age>100)
            {
                printf("You are really old\n");
            }
        }
    }

    /* clean the stream */
    while (getchar() != '\n') {}

    /* pause */
    getchar();

    return 0;
}

Edited 7 Years Ago by Tom Gunn: n/a

It is a normal result of stream I/O in C. The problem is that there is still a character left in the stream after calling scanf(), and getchar() eats it without blocking. The IDE you are using probably closes the window after main() returns, so the window goes away. Calling getchar() is supposed to stop that, but it only works if the stream is clean when getchar() is called.

You can clean the stream with repeated calls to getchar() until '\n' is found. This will produce the right behavior if the stream is not clean, and it will only require an extra [Enter] to be typed if the stream is already clean:

#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
        {
            if(age>100)
            {
                printf("You are really old\n");
            }
        }
    }

    /* clean the stream */
    while (getchar() != '\n') {}

    /* pause */
    getchar();

    return 0;
}

thanx man i appreciate the help

This question has already been answered. Start a new discussion instead.