IntheTrench

Yes or No

Apr 19th, 2024 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | Source Code | 0 0
  1. #include <iostream>
  2.  
  3. char yesOrNo; // stores the yes or no response
  4.  
  5. void userResponse() {
  6.     do {
  7.         std::cout << "Yes or no(y/n): ";
  8.         std::cin >> yesOrNo;
  9.         yesOrNo = std::tolower(yesOrNo); // allows uppercase characters to be entered
  10.     } while (!std::isalpha(yesOrNo));
  11.  
  12.     if (yesOrNo == 'y') {
  13.         std::cout << "You picked yes!";
  14.     }
  15.     else if (yesOrNo == 'n') {
  16.         std::cout << "You picked no!";
  17.     }
  18.     else {
  19.         std::cout << "Invalid Input. Please enter either 'y' or 'n'.";
  20.     }
  21. }
  22.  
  23. int main() {
  24.     userResponse();
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment