0

Ticket Office project

Why am I getting “no output” for this? int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } int ticket = 10; int small; int a = ages [0]; int b = ages [1]; etc to [4] if (a < b && a < c && a < d && a < e) small = a; else if (b < c...) etc else e = small; float disc = small * 0.01; float total = (ticket * 5) * (1.0 - disc); return total; } It works in Code Blocks Also I had to use “if-else-if” because I couldn’t find how to compare multiple values in a switch.

5th Dec 2020, 10:41 PM
Sir Starshine
Sir Starshine - avatar
3 Answers
0
So I just set the small variable to 100, and used the following; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if (ages[i] < small) { small = ages[i]; } This simplified the comparison issue. But it took the answer to an entirely different post to fix the “no output” issue I had. After fixing the rest of the code, I had to do “cout” for the answer again. https://code.sololearn.com/c1QwSR320jnW/?ref=app
16th Dec 2020, 5:55 PM
Sir Starshine
Sir Starshine - avatar
+ 1
Crispy Crunch , why don't you just try to find the younger passenger with loop, without all of the countless conditions you check. For example set the discount variable a big value and in every step of the loop set it to current age if current age is smaller than the discount. As an idea something like this : int disc = 1000; for(int i = 0; i < 5; i++){ if(ages[i] < disc){ disc = ages[i]; } } All after that is easy calculation.
5th Dec 2020, 10:56 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
15th Mar 2021, 2:22 PM
Muzaffar Najib
Muzaffar Najib - avatar