Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // basic integer manipulation
  6. void arithmetic()
  7. {
  8.     cout << "Please enter two integers, separated by a space.\n";
  9.     int num1;
  10.     int num2;
  11.     cin >> num1;
  12.     cin >> num2;
  13.  
  14.     cout << "Sum = " << (num1 + num2) <<
  15.             "\nProduct = " << (num1 * num2) <<
  16.             "\nDifference = " << (num1 - num2) <<
  17.             "\nQuotient = " << (num1 / num2) << "\n";
  18.     return;
  19. }
  20.  
  21. // printing stuff with cout
  22. void printing()
  23. {
  24.     cout << "Printing Exercise:\n";
  25.     cout << "1 2 3 4\n";
  26.     cout << "1 " << "2 " << "3 " << "4\n";
  27.     cout.flush();
  28.     for(int i = 0; i < 4; ++i)
  29.     {
  30.         cout << (i + 1) << " ";
  31.     }
  32.     cout << "\n";
  33.     return;
  34. }
  35.  
  36. // comparing ints
  37. void comparing()
  38. {
  39.     cout << "Please enter two integers, separated by a space.\n";
  40.     int num1;
  41.     int num2;
  42.     cin >> num1;
  43.     cin >> num2;
  44.  
  45.     if(num1 < num2)
  46.     {
  47.         int tempNum = num1;
  48.         num1 = num2;
  49.         num2 = tempNum;
  50.     }
  51.  
  52.     if(num1 == num2)
  53.     {
  54.         cout << num1 << " and " << num2 << " are equal.\n";
  55.     }
  56.     else
  57.     {
  58.         cout << num1 << " is larger, " << num2 << " is smaller.\n";
  59.     }
  60.     cout << "\n";
  61.     return;
  62. }
  63.  
  64. // three variable math
  65. void arithmetic2()
  66. {
  67.     cout << "Please enter three integers, separated by spaces.\n";
  68.     int num1;
  69.     int num2;
  70.     int num3;
  71.     cin >> num1;
  72.     cin >> num2;
  73.     cin >> num3;
  74.     cout << "Sum is " << num1 + num2 + num3 << "\n" <<
  75.             "Average is " << (num1 + num2 + num3) / 3 << "\n" <<
  76.             "Product is " << (num1 * num2 * num3) << "\n" <<
  77.             "Smallest is " << min(num1, min(num2, num3)) << "\n" <<
  78.             "Largest is " << max(num1, max(num2, num3)) << "\n";
  79.     cout << "\n";
  80.     return;
  81. }
  82.  
  83. void circle()
  84. {
  85.     double PI = 3.14159;
  86.     cout << "Please enter an integer.\n";
  87.     int intNum;
  88.     cin >> intNum;
  89.     double dNum = static_cast<double>(intNum);
  90.     cout << "A circle with radius " << intNum << " will have the following measurements:\n" <<
  91.             "  Diameter\t" << 2 * intNum << "\n" <<
  92.             "  Circumference\t" << dNum * PI << "\n" <<
  93.             "  Area\t\t" << PI * (dNum * dNum) << "\n";
  94.     return;
  95. }
  96.  
  97. void digits()
  98. {
  99.     cout << "Please enter a five-digit integer.\n";
  100.     int intNum;
  101.     cin >> intNum;
  102.     int subInt{0};
  103.     string fourSpaces = "    ";
  104.  
  105.     cout << intNum / 10000 << fourSpaces;
  106.  
  107.     subInt = intNum / 10000;
  108.     subInt *= 10000;
  109.     cout << (intNum - subInt) / 1000 << fourSpaces;
  110.  
  111.     subInt = intNum / 1000;
  112.     subInt *= 1000;
  113.     cout << (intNum - subInt) / 100 << fourSpaces;
  114.  
  115.     subInt = intNum / 100;
  116.     subInt *= 100;
  117.     cout << (intNum - subInt) / 10 << fourSpaces;
  118.  
  119.     subInt = intNum / 10;
  120.     subInt *= 10;
  121.     cout << (intNum - subInt) << fourSpaces;
  122.  
  123.     return;
  124. }
  125.  
  126. void bmi()
  127. {
  128.     int weight;
  129.     int height;
  130.     cout << "What is your weight in pounds?\n";
  131.     cin >> weight;
  132.     cout << "What is your height in inches?\n";
  133.     cin >> height;
  134.  
  135.     cout << "Your BMI is " << ((weight * 703) / (height * height)) << ". But it's not a useful number. " <<
  136.             "Get a hold of some body fat calipers if you want a set of meaningful measurements.\n";
  137. }
  138.  
  139. int main()
  140. {
  141.     while(true)
  142.     {
  143.         // print menu
  144.         cout << "1) Arithmetic\n" <<
  145.                 "2) Printing\n" <<
  146.                 "3) Comparing Integers\n" <<
  147.                 "4) Arithmetic 2\n" <<
  148.                 "5) Circle\n" <<
  149.                 "6) Digits of an Integer\n" <<
  150.                 "7) BMI Calculator\n" <<
  151.                 "0) Exit\n" <<
  152.                 "Please make your selection: ";
  153.  
  154.  
  155.         // get user selection
  156.         int selection{0};
  157.         cin >> selection;
  158.  
  159.         // call function
  160.         switch(selection)
  161.         {
  162.             case 1 : arithmetic(); break;
  163.             case 2 : printing(); break;
  164.             case 3 : comparing(); break;
  165.             case 4 : arithmetic2(); break;
  166.             case 5 : circle(); break;
  167.             case 6 : digits(); break;
  168.             case 7 : bmi(); break;
  169.             case 0 : return 0;
  170.             default : cout << "Unknown input\n";
  171.         }
  172.         cout << "\n\n";
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement