0
 printf("Please type Y if you want us to compute the monthly Rate for new data and N otherwise: ");
scanf("%c",&ans);

while ((ans!='y') && (ans!='Y') && (ans!='n') && (ans!='N')){
        printf("Please type Y if you want us to compute the monthly Rate for new data and N otherwise: ");
        scanf("%c",&ans);}

if (ans == 'N' || ans == 'n'){
    printf("Thank you Please visit us again");}
else if (ans == 'Y' || ans == 'y')

While executing this if i enter an n or y it works the right way but if i enter something that isnt an n or y the output lets me input another value but instead of it saying Please type Y if you want us to compute the monthly Rate for new data and N otherwise: it says that twice and i cannot figure out why it would say it twice.

JackV
  • 218
  • 2
  • 12
  • You seem to be missing some `{}` there. – Fred Foo Oct 30 '14 at 15:13
  • `scanf("%c",&ans);}` --> `scanf(" %c",&ans);}` – BLUEPIXY Oct 30 '14 at 15:14
  • 1
    Indent your program properly. Compile it with all warnings & debug info (`gcc -Wall -Wextra -g`). **Use a debugger** (`gdb`) e.g. to run it step by step. And test the result of `scanf` – Basile Starynkevitch Oct 30 '14 at 15:14
  • do some google searches on `scanf` and dirty input buffers... if you enter _"x"_, your `scanf` will only read the _"x"_ from the buffer, leaving the _"\n"_ (enter) in place. The next time around, `\n` will be read, resulting in the behavior you see. I've explained this in more detail [here](http://stackoverflow.com/questions/26144227/c-how-to-handle-user-input-in-a-while-loop) – Elias Van Ootegem Oct 30 '14 at 15:17

0 Answers0