Dec 03 2012, 04:07 AM
Here's what is happening: After inputting the number, you're pressing enter. Enter is a newline character and doesn't actually disappear. The subsequent scanf is using the character to terminate the loop.
The easiest solution is to add a space before %c. I've also added some newlines to cleanup your output.
Try this:
Why isn't anyone else replying anymore?
The easiest solution is to add a space before %c. I've also added some newlines to cleanup your output.
Try this:
Code:
#include <stdio.h>
int main()
{
char another;
int num;
do
{
printf("Enter a number\n");
scanf("%d",&num);
printf("Square of %d is %d\n",num,num*num);
printf("Want to enter another number? y/n\n");
scanf(" %c",&another);
} while(another=='y');
return 0;
}Why isn't anyone else replying anymore?
Steam Wrote: 4:02 PM - George, of the jungle: was out
4:02 PM - George, of the jungle: bison, dude
4:02 PM - Brawl Bashin’ Bison: ???
4:02 PM - George, of the jungle: you're very rude towards alina
4:02 PM - George, of the jungle: how about unbanning her friend?
4:02 PM - George, of the jungle: I mean
4:02 PM - George, of the jungle: it's only gamebanana skins
4:02 PM - Brawl Bashin’ Bison: LOL
4:02 PM - George, of the jungle: ^^
4:02 PM - Brawl Bashin’ Bison: LOLOL
4:02 PM - George, of the jungle: lol


![[-]](https://war-lords.net/forum/images/collapse.png)