Advertisement
Ewerlost

Lab1_C++

Sep 23rd, 2023 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. using namespace std;
  4. int main() {
  5.     char Gen;
  6.     int Age, ReAge;
  7.     bool isNotCorrect = false;
  8.     cout << "This program will find the recommended age for marriage" << '\n' << "Man or Woman ? ENTER M if you are a man or W if you are a woman and your age." << '\n';
  9.  
  10.     do
  11.     {
  12.         cin >> Gen >> Age;
  13.         if (cin.fail()) {
  14.             isNotCorrect = true;
  15.             cout << "Data entered incorrectly, please re-enter" << '\n';
  16.             cin.clear();
  17.             while (cin.get() != '\n');
  18.         }
  19.         else {
  20.             isNotCorrect = false;
  21.             if (Gen != 'M' && Gen != 'W') {
  22.                 cout << "Enter existing gender" << '\n';
  23.                 isNotCorrect = true;
  24.             }
  25.             if (Age < 16 || Age > 100) {
  26.                 cout << "Re-enter with acceptable age(16-100)" << '\n';
  27.                 isNotCorrect = true;
  28.             }
  29.         }
  30.  
  31.     } while (isNotCorrect);
  32.     if (Gen == 'M')
  33.         ReAge = Age / 2 + 7;
  34.     else
  35.         ReAge = Age * 2 - 14;
  36.     cout << "Recommended age of a candidate for marriage : " << ReAge;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement