Get the quotient with decimal using for loop

this has been bugging me for a quite a while now, i'm confused how to get the proper formula to get the correct output

here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  int quotient()
{
	cout << endl;
	cout << "======================= QUOTIENT =======================\n";
    double n, num, quo=1.000;
    cout<<"How many numbers you want to input? ";
    cin>>n;
    for(int i=0; i<n; i++)
    {
    	cout << i+1 << ". ";
        cin>>num;
        quo = quo/num;
    }
    cout<<"\nThe quotient of the "<<n<<" numbers you entered is "<<quo;
    cout<<endl;
    return 0;
}

??? The quotient of 2 numbers is the whole number of times the numerator can be divided by the denominator. eg for 7 / 3, the quotient is 2.

So how does this fit with trying to find the quotient of an arbitrary number of decimal point numbers??

Perhaps if you explained more what you're trying to do.
i'm getting a wrong numbers when i trying to calculate something
here's the output


======================= QUOTIENT =======================
How many numbers you want to input? 3
1. 90
2. 90
3. 90

The quotient of the 3 numbers you entered is 1.37174e-06
But what output are you expecting? What definition of 'quotient' are you using to apply to multiple numbers?
the exact calculations of the user-input numbers
Yes. But what is the 'exact' calculation you are expecting? What answer are you expecting from the given numbers? Why is 1.37174e-06 not considered 'correct'?
I mean

this is my expectations

======================= QUOTIENT =======================
How many numbers you want to input? 2
1. 90
2. 9


The quotient of the 3 numbers you entered is 10



======================= QUOTIENT =======================
How many numbers you want to input? 3
1. 90
2. 9
3. 3


The quotient of the 3 numbers you entered is 3.333
Apparently, quo needs to be initialised as the FIRST number, not as 1.0

Presumably your last example implies that you want 90 / 9 / 3. But it's a daft problem and the "quotient" really only corresponds to an outcome of a single division operation.
Do you mean this:

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
#include <iostream>
using namespace std;

void quotient() {
	cout << "\n======================= QUOTIENT =======================\n";

	double quo {1.0};
	unsigned n {};

	cout << "How many numbers you want to input? ";
	cin >> n;

	for (unsigned i {}; i < n; ++i) {
		double num {};

		cout << i + 1 << ". ";

		if (i) {
			cin >> num;
			quo /= num;
		} else
			cin >> quo;
	}

	cout << "\nThe quotient of the " << n << " numbers you entered is " << quo << '\n';
}

int main() {
	quotient();
}



======================= QUOTIENT =======================
How many numbers you want to input? 3
1. 90
2. 9
3. 3

The quotient of the 3 numbers you entered is 3.33333

Last edited on
quo was initialized as 1.0 first. So when you input numbers. For example,
1. 90
2. 9
3. 3
It actually executed like this: 1.0 / 90 / 9 / 3 . That's not what you expected.
ohhh i just realized that, thank you! i solved my problem thanks ningfan666
Topic archived. No new replies allowed.