Advertisement
aod6060

How much do you have?

May 6th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string name;
  9.     int age = -1;
  10.     float balance = 0.0f;
  11.    
  12.     cout << "Please type in your name: ";
  13.     getline(cin, name);
  14.    
  15.     while(name.empty()) {
  16.         cout << "Invalid name, it need to atleast not be empty" << endl;
  17.         getline(cin, name);
  18.     }
  19.    
  20.     cout << "Please type in your age: ";
  21.     cin >> age;
  22.    
  23.     while(age < -1 || age > 120) {
  24.         cout << "Invalid age please type in an age between 0 to 119: " << endl;
  25.         cin >> age;
  26.     }
  27.    
  28.     cout << "Please type in you're balance: ";
  29.     cin >> balance;
  30.    
  31.     while(balance < 0.0f) {
  32.         cout << "Invalid balance please type a balance, any amout thats not less than zero." << endl;
  33.         cin >> balance;
  34.     }
  35.    
  36.    
  37.     cout << endl;
  38.    
  39.     cout << "Hello " << name << " and your age is " << age << endl;
  40.    
  41.     cout << "and you have $" << setiosflags(ios::fixed) << setprecision(2) << balance << " in your bank account!!!" << endl;
  42.     cout << endl;
  43.     cout << endl;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement