Write a Program which will do the following. 1. Ask the User to Enter two whole
ID: 3562104 • Letter: W
Question
Write a Program which will do the following.
1. Ask the User to Enter two whole numbers.
2.Display the following (All as whole numbers)
a. The original two numbers
b. The sum of the two numbers
c. The result of the first number divided by the second number
d. The remainder of the first number divided by the second number
e. The result of the first number times the second number
f. The result of the first number minus the second number.
3) Ask the user for two fractional numbers
4) Display the following (All as fractional numbers):
a. The original two numbers.
b. The sum of the two numbers
c. The result of the first number divided by the second number
d. The result of the first number times the second number
e. The result of the first number minus the second number.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
int dec1, dec2;
int tmp, comm;
char c;
// Ask the User to Enter two whole numbers.
cout << "Enter 2 numbers: " << endl;
cin >> num1 >> num2;
// The original two numbers
cout << "first number is " << num1 << endl;
cout << "second number is " << num2 << endl;
// The sum of the two numbers
cout << "Sum of the numbers is "<< (num1 + num2) << endl;
// The result of the first number divided by the second number
cout << "Division of the numbers is "<< (num1 / num2) << endl;
// The remainder of the first number divided by the second number
cout << "Reminder of the numbers is "<< (num1 % num2) << endl;
// The result of the first number times the second number
cout << "Multiply of the numbers is "<< (num1 * num2) << endl;
// The result of the first number minus the second number.
cout << "Subtract of the numbers is "<< (num1 - num2) << endl;
// Ask the user for two fractional numbers
cout << "Enter Values in this form 2/3 94/3: ";
cin >> num1 >> c >> dec1 >> num2 >> c >> dec2;
// The original two numbers.
//b. The sum of the two numbers
cout << "first number is " << num1 << "/" << dec1 << endl;
cout << "second number is " << num2 << "/" << dec2 << endl;
cout << "Division of the numbers is "<< (num1 * dec2) << "/" << (dec1 * num2) << endl;
// The result of the first number times the second number
cout << "Multiply of the numbers is "<< (num1 * num2) << "/" << (dec1 * dec2) << endl;
// The result of the first number minus the second number.
comm = dec1 * dec2;
cout << "Subtract of the numbers is "<< (num1 * dec2 - num2 * dec1) << "/" <<comm << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.