Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // basic integer manipulation
- void arithmetic()
- {
- cout << "Please enter two integers, separated by a space.\n";
- int num1;
- int num2;
- cin >> num1;
- cin >> num2;
- cout << "Sum = " << (num1 + num2) <<
- "\nProduct = " << (num1 * num2) <<
- "\nDifference = " << (num1 - num2) <<
- "\nQuotient = " << (num1 / num2) << "\n";
- return;
- }
- // printing stuff with cout
- void printing()
- {
- cout << "Printing Exercise:\n";
- cout << "1 2 3 4\n";
- cout << "1 " << "2 " << "3 " << "4\n";
- cout.flush();
- for(int i = 0; i < 4; ++i)
- {
- cout << (i + 1) << " ";
- }
- cout << "\n";
- return;
- }
- // comparing ints
- void comparing()
- {
- cout << "Please enter two integers, separated by a space.\n";
- int num1;
- int num2;
- cin >> num1;
- cin >> num2;
- if(num1 < num2)
- {
- int tempNum = num1;
- num1 = num2;
- num2 = tempNum;
- }
- if(num1 == num2)
- {
- cout << num1 << " and " << num2 << " are equal.\n";
- }
- else
- {
- cout << num1 << " is larger, " << num2 << " is smaller.\n";
- }
- cout << "\n";
- return;
- }
- // three variable math
- void arithmetic2()
- {
- cout << "Please enter three integers, separated by spaces.\n";
- int num1;
- int num2;
- int num3;
- cin >> num1;
- cin >> num2;
- cin >> num3;
- cout << "Sum is " << num1 + num2 + num3 << "\n" <<
- "Average is " << (num1 + num2 + num3) / 3 << "\n" <<
- "Product is " << (num1 * num2 * num3) << "\n" <<
- "Smallest is " << min(num1, min(num2, num3)) << "\n" <<
- "Largest is " << max(num1, max(num2, num3)) << "\n";
- cout << "\n";
- return;
- }
- void circle()
- {
- double PI = 3.14159;
- cout << "Please enter an integer.\n";
- int intNum;
- cin >> intNum;
- double dNum = static_cast<double>(intNum);
- cout << "A circle with radius " << intNum << " will have the following measurements:\n" <<
- " Diameter\t" << 2 * intNum << "\n" <<
- " Circumference\t" << dNum * PI << "\n" <<
- " Area\t\t" << PI * (dNum * dNum) << "\n";
- return;
- }
- void digits()
- {
- cout << "Please enter a five-digit integer.\n";
- int intNum;
- cin >> intNum;
- int subInt{0};
- string fourSpaces = " ";
- cout << intNum / 10000 << fourSpaces;
- subInt = intNum / 10000;
- subInt *= 10000;
- cout << (intNum - subInt) / 1000 << fourSpaces;
- subInt = intNum / 1000;
- subInt *= 1000;
- cout << (intNum - subInt) / 100 << fourSpaces;
- subInt = intNum / 100;
- subInt *= 100;
- cout << (intNum - subInt) / 10 << fourSpaces;
- subInt = intNum / 10;
- subInt *= 10;
- cout << (intNum - subInt) << fourSpaces;
- return;
- }
- void bmi()
- {
- int weight;
- int height;
- cout << "What is your weight in pounds?\n";
- cin >> weight;
- cout << "What is your height in inches?\n";
- cin >> height;
- cout << "Your BMI is " << ((weight * 703) / (height * height)) << ". But it's not a useful number. " <<
- "Get a hold of some body fat calipers if you want a set of meaningful measurements.\n";
- }
- int main()
- {
- while(true)
- {
- // print menu
- cout << "1) Arithmetic\n" <<
- "2) Printing\n" <<
- "3) Comparing Integers\n" <<
- "4) Arithmetic 2\n" <<
- "5) Circle\n" <<
- "6) Digits of an Integer\n" <<
- "7) BMI Calculator\n" <<
- "0) Exit\n" <<
- "Please make your selection: ";
- // get user selection
- int selection{0};
- cin >> selection;
- // call function
- switch(selection)
- {
- case 1 : arithmetic(); break;
- case 2 : printing(); break;
- case 3 : comparing(); break;
- case 4 : arithmetic2(); break;
- case 5 : circle(); break;
- case 6 : digits(); break;
- case 7 : bmi(); break;
- case 0 : return 0;
- default : cout << "Unknown input\n";
- }
- cout << "\n\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement