ticket office is difficult (I can't do this) | SoloLearn: Learn to code for FREE!

+1

ticket office is difficult (I can't do this)

I coded here. #include <iostream> using namespace std; int main() { int ages[5]; double minage; // for (int i = 0; i < 5; ++i) { // cin >> ages[i]; // } ages[0] = 27; ages[1] = 20; ages[2] = 14; ages[3] = 40; ages[4] = 50; for(int i = 0; i < 5; ++i) { if(ages[i] < 0) {cout << "age is plus"; return 0;} } //your code goes here if(ages[0] <= ages[1]) { if(ages[0] <= ages[2]) { if(ages[0] <= ages[3]) { if(ages[0] <= ages[4]) { minage = ages[0]; if(50.0 - 0.5 * minage < 0) {cout << 0.0; return 0;} cout << 50.0 - 0.5 * minage << endl; } } } } if(ages[1] <= ages[0]) { if(ages[1] <= ages[2]) { if(ages[1] <= ages[3]) { if(ages[1] <= ages[4]) { minage = ages[1]; if(50.0 - 0.5 * minage < 0) {cout << 0.0; return 0;} cout << 50.0 - 0.5 * minage << endl; } } } } if(ages[2] <= ages[0]) { if(ages[2] <= ages[1]) { if(ages[2] <= ages[3]) { if(ages[2] <= ages[4]) { minage = ages[2]; if(50.0 - 0.5 * minage < 0) {cout << 0.0; return 0;} cout << 50.0 - 0.5 * minage << endl; } } } } if(ages[3] <= ages[0]) { if(ages[3] <= ages[1]) { if(ages[3] <= ages[2]) { if(ages[3] <= ages[4]) { minage = ages[3]; if(50.0 - 0.5 * minage < 0) {cout << 0.0; return 0;} cout << 50.0 - 0.5 * minage << endl; } } } } if(ages[4] <= ages[0]) { if(ages[4] <= ages[1]) { if(ages[4] <= ages[2]) { if(ages[4] <= ages[3]) { minage = ages[4]; if(50.0 - 0.5 * minage < 0) {cout << 0.0; return 0;} cout << 50.0 - 0.5 * minage << endl; } } } } return 0; } I cannot do this with test 3. Why? If age is NOT zero from 100, how do I do? Or, please show me the test 3's input data? :) I will use pen and paper....

1/4/2021 9:31:58 AM

slowlearner

9 Answers

New Answer

+4

Here try this #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here float m; float p; m = ages[0]; for (int x = 1; x < 5; ++x) { if ( m > ages[x]) { m = ages[x]; } } p = 50 - (50*m/100); cout << p << endl; return 0; }

+4

slowlearner because you said you can't do it..

+4

slowlearner did it work?

+4

Use the three dots in the answer

0

thanks! but why?

0

0

0

What is a tick?

0

can someone explain why the solution code given by a commenter is correct? I dont get it