Hope someone could help me on this one, thanks in advanced!

My objective is to repeat an input until the user hit/press the letter 'N'

But the problem is when it comes to the part of answering the question:

"Add Another Number? [Y/N]"

the program stops!

Here's my faulty code: :(


int main()


	int num1, num2, total;
	char ans;


	do {
		printf("Enter first number: ");
		scanf("%d", &num1);

		printf("Enter second number: ");
		scanf("%d", &num2);

		total = num1 + num2;

		printf("\nTotal is: %d \n", total);

		printf("\nAdd another number? [Y/N]: ");

	} while (ans != 'N');




Thanks again to all!

Recommended Answers

All 3 Replies


at line 27 use %s instead of %c

commented: I don't think thats gonna help instead complicates the problem. -1

%c is preceded with a white-space character.
Like this:

scanf(" %c",&ans);

You might remove


Hope to help you.

thanks again people! ^_^ it works now..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.