0

Need help with ticket office module

The first three test cases work but the fourth and fifth donā€™t. I tested the code outside of the module and it has worked with all of my random inputs but I think Iā€™m missing something. An explanation as to what Iā€™ve done wrong would be appreciated. https://code.sololearn.com/cCSBYgs2hLHe/?ref=app

23rd Apr 2021, 9:07 PM
Mason
4 Answers
+ 6
#include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } int lowAge = ages[0]; for (int x = 1; x < 5; ++x){ if (lowAge > ages[x]){ lowAge = ages[x]; } } double dis = (lowAge / 100.00) * 50.00; cout << 50 - dis << endl; return 0; }
23rd Apr 2021, 9:19 PM
RKK
RKK - avatar
+ 7
the variable f is removed as it was useless. I think the error was because your lowAge was set to 500.(not sure but we don't know the other test cases so its better to not set any raw value here) And since we have set lowAge to ages[0], we don't need to compare it again so we start the for loop with x=1 Notice in dis how 100 and 50 are changed to 100.00 and 50.00, why? Because that's helpful as it will make the result a double type.
23rd Apr 2021, 9:22 PM
RKK
RKK - avatar
+ 1
Mason Try this: include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } double youngest = ages[0]; for (int a = 0; a <5; ++a) { if(youngest>ages[a]) { youngest = ages[a]; } } double prezzo = 50 - (50*youngest/100); cout << prezzo; return 0; }
23rd Apr 2021, 10:41 PM
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø - avatar
0
Rkk, your explanation helped clear up some points i wasnt understanding. I wasnt sure how to find the lowest number in an array. Thanks.
24th Apr 2021, 3:05 AM
Mason