0

Why this doesn't work?

https://code.sololearn.com/cPIVyM65YiDx/?ref=app I'm trying to do the "taquilla" exercise from C++, but my code doesn't work, and I don't know why. Can anyone help me? You are working on a ticket system. A ticket costs 10 dollars. The office is running a discount campaign: each group of 5 people receives a discount, which is determined based on the age of the youngest person in the group. You need to create a schedule that takes the ages of all 5 people as input and outputs the total price of the tickets. Input example: 55 28 fifteen 38 63 Output example: 42.5 The youngest age is 15, so the group gets a 15% discount off the total price, which is $50 - 15% = $42.5 These are one of the inputs and outputs of one of the examples (some of these examples have good answers in my code, but others not) input: 11 18 19 22 49 my output: 48 the right output: 44.5

22nd Jun 2022, 11:22 PM
javier
4 Réponses
+ 1
Javier, Here's my version int main() { int ages[ 5 ]; cin >> ages[ 0 ]; // read in first visitor's age (ages[ 0 ]) int joven = ages[ 0 ]; // assume first visitor is youngest for ( int i = 1; i < 5;++i ) // read the next 4 visitors' ages { cin >> ages[ i ]; if( ages[ i ] < joven ) // if any visitor were younger { joven = ages[ i ]; // adjust <joven> accordingly } } cout << 50.0 * ( 100 - joven ) / 100 << endl; // calculate total price return 0; }
23rd Jun 2022, 2:19 PM
Ipang
+ 1
I haven't tried this one, can you add the task Description in your post's Description above so I can understand it?
23rd Jun 2022, 11:24 AM
Ipang
+ 1
Done Ipang
23rd Jun 2022, 12:39 PM
javier
+ 1
Thanks! Ipang
23rd Jun 2022, 4:32 PM
javier