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