Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to add a record without quitting the program using loop function?

madmhan84madmhan84 Member Posts: 16
[B]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[/B]

[CODE]
#include
#include

int main()

{

int num1, num2, total;
char ans;


clrscr();


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

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

total = num1 + num2;

printf("
Total is: %d", total);

printf("Add another number? [Y/N]: ");
scanf("%c",&ans);


} while (ans != 'N');


getch();

return(0);

}
[/CODE]

[B]Thanks again![/B]
Sign In or Register to comment.