Help understanding this problem

closed account (9G3v5Di1)
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?
For example, the user enter "10 2 3 5 9 3", and the program outputs 5, 0, and 3.
Yes, the wording isn't great.
closed account (9G3v5Di1)
thank you
closed account (9G3v5Di1)
couldn't get the logic..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include "_pause.h"

using namespace 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;
}
Last edited on
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';
}
Last edited on
closed account (9G3v5Di1)
what is the use of std:: before cin and cout?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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/div
int quotient( int a, int b ) { return a / b; }

int main() {

    const int 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" ;
        }
    }
}
> what is the use of std:: before cin and cout?

See: http://www.cplusplus.com/forum/beginner/142171/#msg750694
closed account (9G3v5Di1)
noted on this. thank you so much
Topic archived. No new replies allowed.