SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | #include <cstdlib> | |
| 3 | ||
| 4 | using namespace std; | |
| 5 | ||
| 6 | int main (void) | |
| 7 | {
| |
| 8 | - | float zero_qty = 0.0, pro_of_neg = 1.0, val; |
| 8 | + | float pro_of_neg = 1.0, val; |
| 9 | - | int neg_qty = 0; |
| 9 | + | int neg_qty = 0, zero_qty = 0; |
| 10 | cout << "enter a value or ctrl+z to end: "; | |
| 11 | cin >> val; | |
| 12 | ||
| 13 | while (!cin.eof()) | |
| 14 | {
| |
| 15 | if (val == 0.0) | |
| 16 | zero_qty++; | |
| 17 | if (val < 0.0) | |
| 18 | {
| |
| 19 | neg_qty++; | |
| 20 | pro_of_neg *= val; | |
| 21 | } | |
| 22 | ||
| 23 | cout << "enter a value or ctrl+z to end: "; | |
| 24 | cin >> val; | |
| 25 | } | |
| 26 | ||
| 27 | if (neg_qty > 1) | |
| 28 | cout << "\nproduct of negative elements: " << pro_of_neg << endl; | |
| 29 | else | |
| 30 | cout << "\nare no negative elements or too few values!" << endl; | |
| 31 | ||
| 32 | - | if (zero_qty > 0.0) |
| 32 | + | if (zero_qty > 0) |
| 33 | cout << "\nquantity of zero elements: " << zero_qty << endl; | |
| 34 | else | |
| 35 | cout << "\nare no zero elements!" << endl; | |
| 36 | ||
| 37 | system("pause");
| |
| 38 | return 0; | |
| 39 | } |