Write a program that can divide six non-zero integers (two integers per division) from the user and display the result to the user. Create a function that will perform the division operation. Display only the non-decimal part of the quotient.
Anyone? What does this "a program that can divide six non-zero integers (two integers per division)" mean?
#include <iostream>
#include "_pause.h"
usingnamespace std;
int divide(int q, int w, int e, int r, int t, int y){
int quotientOne = q / w;
int quotientTwo = e / r;
int quotientThree = t / y;
return quotientOne, quotientTwo, quotientThree;
}
int main(){
int n[6];
for(int i = 0; i<6; i++){
cout << "Enter a number[" << i + 1 << "]: ";
cin >> n[i];
}
int total = divide(n[0], n[1], n[2], n[3], n[4], n[5]);
cout << "The quotients per pair are: " << total;
cout << endl;
_pause();
return 0;
}
You're making this more complicated than it needs to be:
1 2 3 4 5 6 7
#include <iostream>
int div(int a, int b) { return a / b; }
int main() {
int a, b, c, d, e, f;
if (std::cin >> a >> b >> c >> d >> e >> f)
std::cout << div(a, b) << ' ' << div(c, d) << ' ' << div(e, f) << '\n';
}
#include <iostream>
// if this function is at global scope, avoid the name 'div'
// name clash if std::div is also exposed as ::div
// see: https://en.cppreference.com/w/cpp/numeric/math/divint quotient( int a, int b ) { return a / b; }
int main() {
constint NUM_DIVISIONS = 3 ;
for( int i = 0 ; i < NUM_DIVISIONS ; ++i ) {
int a, b ;
if( std::cin >> a >> b ) {
// avoid integer division by zero (it engenders undefined behaviour)
if( b != 0 ) std::cout << quotient(a,b) << '\n' ;
else std::cout << "can't divide by zero!\n" ;
}
}
}