Can you help me out with this please? it needs to be in the c++ language. Thank
ID: 3728070 • Letter: C
Question
Can you help me out with this please? it needs to be in the c++ language. Thank you.
Division calculator.
a) Request two integer values for the numerator and denominator.
b) Use a validation loop to insure that denominator is not equal to 0.
c) Output the result of the following operations:
1) regular division
2) integer division
3) modulo division
Output Example
Enter an integer value for the numerator: 10
Enter an integer for the denominator: 0
0 is not a valid denominator.
Enter an integer for the denominator: 3
1) regular division: 3.33333
2) integer division: 3
3) modulo division: 1
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
int n,d;
cout<<"Enter an integer value for the numerator: " << endl;
cin >> n;
cout<<"Enter an integer for the denominator: "<<endl;
cin>> d;
while(d==0) {
cout<<"0 is not a valid denominator. "<<endl;
cout<<"Enter an integer for the denominator: "<<endl;
cin>> d;
}
cout<<"1) regular division: "<<n/(double)d<<endl;
cout<<"2) integer division: "<<n/d<<endl;
cout<<"3) modulo division: "<<n%d<<endl;
}
Output:
Enter an integer value for the numerator: 10
Enter an integer for the denominator: 0
0 is not a valid denominator. 3
Enter an integer for the denominator:
1) regular division: 3.33333
2) integer division: 3
3) modulo division: 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.