SHARE
TWEET

Untitled

a guest Jun 19th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. double TheMax( double number1, double number2)
  7. {
  8.     if (number1 > number2)
  9.         return number1;
  10.     else
  11.         return number2;
  12.  
  13. }
  14. double TheMax( double number1, double number2, double number3)
  15. {
  16.     return max(max(number1, number2),number3);
  17. }
  18.  
  19. int main()
  20. {
  21.     double number1, number2, number3 = 0;
  22.     double svar = 0;
  23.     int howManyNumbers = 0;
  24.     char doAgain;
  25.    do
  26.    {
  27.     cout << "How Many numbers do you want?: ";
  28.     cin >> howManyNumbers;
  29.     if(howManyNumbers < 2 || howManyNumbers > 3)
  30.     {
  31.         cout << "You can only enter 2 or 3 numbers, try again." << endl;
  32.         cin.clear(); //Hreinsar strauminn
  33.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  34.         continue;
  35.     }
  36.     else
  37.     {
  38.         cout << "You picked "<< howManyNumbers << " numbers." << endl;
  39.     }
  40.  
  41.         if (howManyNumbers == 2)
  42.         {
  43.             cout << "Tell me the two numbers: " << endl;
  44.             cin >> number1;
  45.             cin >> number2;
  46.             svar = TheMax( number1, number2);
  47.             cout << "The highest number of those two is: " << svar;
  48.         }
  49.         else
  50.         {
  51.             cout << "Tell me the three numbers: " << endl;
  52.             cin >> number1;
  53.             cin >> number2;
  54.             cin >> number3;
  55.             svar = TheMax(number1, number2, number3);
  56.             cout << "The highest number of those three is: " << svar;
  57.         }
  58.         cout << '\n' <<"Press Y to do again or N to quit" << endl;
  59.         cin >> doAgain;
  60.  
  61.     double number1, number2, number3 = 0;
  62.     double svar = 0;
  63.     int howManyNumbers = 0;
  64.  
  65.     }while (doAgain == 'y' || doAgain == 'Y');
  66.     return 0;
  67. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top