THIS IS USING C++ Pay special attention to the style of your code. Indent your c
ID: 3889207 • Letter: T
Question
THIS IS USING C++
Pay special attention to the style of your code. Indent your code correctly, choose
meaningful names for your variables, define constants where needed, choose most
suitable control statements, etc.
Question 1:
Write a program that reads from the user two positive integers, and prints the result of
when we add, subtract multiply, divide, div and mod them.
Your program should interact with the user exactly as it shows in the following example:
Please enter two positive integers, separated by a space:
14 4
14 + 4 = 18
14 – 4 = 10
14 * 4 = 56
14 / 4 = 3.5
14 div 4 = 3
14 mod 4 = 2
Explanation / Answer
Hi Let me know if you need more information:-
=====================================
#include <iostream>
using namespace std;
int main() {
int inputNumber1 = 0;
int inputNumber2 = 0;
cout << "Please enter two positive integers, separated by a space:" << endl;
cin >> inputNumber1 >> inputNumber2;
cout << inputNumber1 << " + " << inputNumber2 << " = " <<(inputNumber1 + inputNumber2)<<endl;
cout << inputNumber1 << " - " << inputNumber2 << " = " <<(inputNumber1 - inputNumber2)<<endl;
cout << inputNumber1 << " * " << inputNumber2 << " = " <<(inputNumber1 * inputNumber2)<<endl;
cout << inputNumber1 << " / " << inputNumber2 << " = " <<(inputNumber1 /(float) inputNumber2)<<endl;
cout << inputNumber1 << " div " << inputNumber2 << " = " <<(inputNumber1 / inputNumber2)<<endl;
cout << inputNumber1 << " mod " << inputNumber2 << " = " <<(inputNumber1 % inputNumber2)<<endl;
return 0;
}
==================
OUTPUT:-
=====================
Please enter two positive integers, separated by a space:
14 4
14 + 4 = 18
14 - 4 = 10
14 * 4 = 56
14 / 4 = 3.5
14 div 4 = 3
14 mod 4 = 2
====================================
Thanks
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.