Question

I have written a simple "hello, world" program from here http://www.cprogramming.com/tutorial/c/lesson1.html cprogramming: lesson 1, the output is shown then the terminal prompt shows up in the following one. When executing another program:

#include <stdio.h>

main()
{
int age;
printf("How old are you?");
scanf("%d", &age);
if (age <= 20) 
{
printf("You are still young");
}
else if (age >= 20)
printf("You are not that young anymore!");
else if (age >= 30)
printf("Hello young man!\n");
getchar();
return 0;
}

The output is shown in the same line as the terminal prompt in Gnome Terminal 3.6.1 on Ubuntu 13.10. I just don't know if this a code issue or is it related to the terminal only.

Was it helpful?

Solution 2

Add a newline character after each of your printf's

example:

int age;
printf("How old are you?\n");
scanf("%d", &age);

OTHER TIPS

Alignment can be done using escape sequences. In your case u need to use \n for new line

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top