Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char yesOrNo; // stores the yes or no response
- void userResponse() {
- do {
- std::cout << "Yes or no(y/n): ";
- std::cin >> yesOrNo;
- yesOrNo = std::tolower(yesOrNo); // allows uppercase characters to be entered
- } while (!std::isalpha(yesOrNo));
- if (yesOrNo == 'y') {
- std::cout << "You picked yes!";
- }
- else if (yesOrNo == 'n') {
- std::cout << "You picked no!";
- }
- else {
- std::cout << "Invalid Input. Please enter either 'y' or 'n'.";
- }
- }
- int main() {
- userResponse();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment