1
I have the following variable :
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
char op;
And I’m asking the user to enter a character :
printf("\nDeseja realizar novo teste (s/n) ?");
op = getche();
If the user types s
the following code will appear :
printf("\nDigite um número para o dividendo : \n");
scanf("%d", ÷ndo);
printf("\nDigite um número para o divisor : \n");
scanf("%d", &divisor);
And if the user type n
, the program leaves, but if you type any other character, it appears, the same message asking you to perform new test.
Code :
do {
printf("\nDeseja realizar novo teste (s/n) ?");
op = getche();
}while(getche() != 's' || getche != 'n');
He keeps running the do-while
, even if I put the characters s
or n
, how can I make it work ?
I prefer to use scanf too, but it’s a college exercise, and clearly asks to use getche, even if I don’t want to use it. And he’s just giving problems with the getche().
– Mondial
Try to use an infinite loop and check the character with
if
. Test here with Visual Studio 2015 and it worked. I updated the code.– Ossetian_Odin
Yes, it worked. Thank you very much.
– Mondial