0
Using while statement ask the user to input a character, accept only character Y or N.
If other character are inputted ask the user to enter another character.
3 Respuestas
+ 2
#include <iostream>
using namespace std;
int main() {
char input;
cout<<"Enter yes or no(Y/N)? ";
cin >> input;
// if input not == N or input not == Y return input else(input == to N/Y) cout<<"Successfuly";
while(!(input=='N' or input=='Y')) {
cout<<"Enter yes or no(Y/N)? ";
cin >> input;
}
cout<<"Successfuly!"<<endl;
return 0;
}
+ 1
Show me your code and I'll try to help you make it work.
#include <iostream>
int main()
{
char res;
while( std::cin >> res && ( res != 'Y' && res != 'N' ) )
{
std::cout << "Enter Y or N please\n";
}
std::cout << res;
return 0;
}
https://www.sololearn.com/post/75089/?ref=app
(Edited)