Advertisement
zCool

Test 2: How much you got?

May 3rd, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. std::string  name;
  7. int age;
  8. float money;
  9. std::string exitStr = "";
  10.  
  11. std::cout << "/-------------------------------------------------"   << "\n"
  12.           << "-- Please enter your name: ";
  13.  
  14. while(true)
  15. {
  16.     if (std::cin >> name)
  17.     {
  18.        break;
  19.     }
  20.     else
  21.     {
  22.         std::cin.clear();
  23.         std::cin.ignore();
  24.         std::cout << "Sorry I didn't get that please enter your name: ";
  25.     }
  26. }
  27.  
  28. std::cout << "-- Please enter your age: ";
  29.  
  30. while(true)
  31. {
  32.     if (std::cin >> age)
  33.     {
  34.         if(age <0)
  35.         {
  36.             std::cin.clear();
  37.             std::cin.ignore();
  38.             std::cout << "Please enter a real age: ";
  39.         }
  40.         else
  41.         {
  42.             break;
  43.         }
  44.     }
  45.     else
  46.     {
  47.         std::cin.clear();
  48.         std::cin.ignore();
  49.         std::cout << "Sorry I didn't get that please enter your age: ";
  50.     }
  51. }
  52. std::cout << "-- Please enter how much money you have: ";
  53.  
  54. while(true)
  55. {
  56.     if (std::cin >> money)
  57.     {
  58.         if (money < 0)
  59.         {
  60.             std::cin.clear();
  61.             std::cin.ignore();
  62.             std::cout << "Sounds like you are in debt, probably college loans huh, but please enter zero in this case: ";
  63.         }
  64.         else
  65.         {
  66.             break;
  67.         }
  68.     }
  69.     else
  70.     {  
  71.         std::cin.clear();
  72.         std::cin.ignore();
  73.         std::cout << "Sorry I didn't get that please enter your savings: ";
  74.     }
  75. }
  76.  
  77. std::cout << " Your name is: " << name << "\n";
  78. std::cout << " Your age is: " << age << "\n";
  79. std::cout << " Your savings is: " << money << "\n";
  80. std::cout << "/-------------------------------------------------" << "\n";
  81.  
  82. system("PAUSE");
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement