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
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'?
======================= 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.
#include <iostream>
usingnamespace 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
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.