Advertisement
Guest User

Week2

a guest
Mar 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. // Week2_Buehler.cpp : Week 2 Assignments.
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. /// 2.16
  8. int main()
  9. {
  10.     int a, b;
  11.     cout << "Please enter 2 integers: ";
  12.     cin >> a >> b;
  13.     cout << "The values you entered were: " << a << " and " << b << endl;
  14.     cout << "The sum of the values: " << a + b << endl;
  15.     cout << "The difference of the values: " << a - b << endl;
  16.     cout << "The product of the values: " << a * b << endl;
  17.     cout << "The quotient of the values: " << a / b << endl;
  18.     return 0;
  19. }
  20.  
  21. /// 2.17
  22. int main()
  23. {
  24.     cout << "1 2 3 4\n";
  25.     cout << "1" << " 2" << " 3" << " 4\n";
  26.     cout << "1";
  27.     cout << " 2";
  28.     cout << " 3";
  29.     cout << " 4\n";
  30.  
  31.     return 0;
  32. }
  33.  
  34. /// 2.18
  35. int main()
  36. {
  37.     int a, b;
  38.     cout << "Please enter 2 integers: ";
  39.     cin >> a >> b;
  40.     if (a == b)
  41.         cout << "The numbers are equal.\n";
  42.     else if (a > b)
  43.         cout << a << " is the larger number.\n";
  44.     else
  45.         cout << b << " is the larger number.\n";
  46.     return 0;
  47. }
  48.  
  49. /// 2.19
  50. int main()
  51. {
  52.     int a, b, c;
  53.     cout << "Input three different integers: ";
  54.     cin >> a >> b >> c;
  55.  
  56.     int sum = a + b + c;
  57.     int avg = sum / 3;
  58.     int prd = a * b * c;
  59.  
  60.     int sml = a;
  61.     int lrg = a;
  62.  
  63.     if (b < sml) sml = b;
  64.     if (c < sml) sml = c;
  65.  
  66.     if (b > lrg) lrg = b;
  67.     if (b > lrg) lrg = c;
  68.  
  69.     cout << "Sum is " << sum << endl;
  70.     cout << "Average is " << avg << endl;
  71.     cout << "Product is " << prd << endl;
  72.     cout << "Smallest is " << sml << endl;
  73.     cout << "Largest is " << lrg << endl;
  74.     return 0;
  75. }
  76.  
  77. /// 2.20
  78. int main()
  79. {
  80.     const float pi = 3.14159;
  81.     int r;
  82.     cout << "Please enter the radius of a circle: ";
  83.     cin >> r;
  84.     cout << "Diameter: " << 2 * r << "\n";
  85.     cout << "Circumference: " << 2 * pi * r << "\n";
  86.     cout << "Area: " << pi * r * r << "\n";
  87.     return 0;
  88. }
  89.  
  90. /// 2.28
  91. int main()
  92. {
  93.     int n;
  94.  
  95.     cout << "Enter a five-digit number: ";
  96.     cin >> n;
  97.     cout << n / 10000 << "   ";
  98.     n = n % 10000;
  99.     cout << n / 1000 << "   ";
  100.     n = n % 1000;
  101.     cout << n / 100 << "   ";
  102.     n = n % 100;
  103.     cout << n / 10 << "   ";
  104.     n = n % 10;
  105.     cout << n / 1 << "\n";
  106.  
  107.     return 0;
  108. }
  109.  
  110. /// 2.30
  111. int main()
  112. {
  113.     int weight, height;
  114.     cout << "Please enter your weight (in pounds): ";
  115.     cin >> weight;
  116.     cout << "Please enter your height (in inches): ";
  117.     cin >> height;
  118.     float bmi;
  119.     bmi = weight * 703.0 / (height * height);
  120.     cout << "Your BMI: " << bmi << "\n\n";
  121.     cout << "BMI VALUES\n";
  122.     cout << "Underweight: less than 18.5\n";
  123.     cout << "Normal:      between 18.5 and 24.9\n";
  124.     cout << "Overweight:  between 25 and 29.9\n";
  125.     cout << "Obese:       30 or greater\n";
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement