>>Why does it jump back to the turbo c window when I press enter to enter my age? Is this wrong?
because you didn't tell the program to do anything else. If you want it to wait so that you can see what's on the screen, put a getch() at the end so that it will wait for keybord input.
After calling scanf() with an integer, the scanf() function does not remove the <Enter> key from the keyboard buffer. You must flush the input buffer or else the program won't wait for the next getch() .
int main()
{
float years, days;
printf ("Please type your age in years:");
scanf ( "%f", &years);
getchar(); // remove '\n' from keyboard buffer
days = years * 365;
printf ("You are%.1f days old.\n", days);
getchar();
return 0;
} Last edited by Ancient Dragon; Sep 21st, 2006 at 8:43 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,950 posts
since Aug 2005