+ 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....

4th Jan 2021, 9:31 AM
slowlearner
slowlearner - avatar
9 Respuestas
+ 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; }
4th Jan 2021, 11:06 AM
VṢtēphen
VṢtēphen - avatar
+ 4
slowlearner because you said you can't do it..
4th Jan 2021, 11:20 AM
VṢtēphen
VṢtēphen - avatar
+ 4
slowlearner did it work?
4th Jan 2021, 11:21 AM
VṢtēphen
VṢtēphen - avatar
+ 4
Use the three dots in the answer
4th Jan 2021, 11:29 AM
VṢtēphen
VṢtēphen - avatar
0
thanks! but why?
4th Jan 2021, 11:18 AM
slowlearner
slowlearner - avatar
0
ok
4th Jan 2021, 11:20 AM
slowlearner
slowlearner - avatar
0
Yes!
4th Jan 2021, 11:21 AM
slowlearner
slowlearner - avatar
0
What is a tick?
4th Jan 2021, 11:24 AM
slowlearner
slowlearner - avatar
0
can someone explain why the solution code given by a commenter is correct? I dont get it
4th Jan 2021, 10:49 PM
Mohand Abdel-Fattah
Mohand Abdel-Fattah - avatar