Need some help please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need some help please

How can i get the youngest age ? You are working on a ticketing system. A ticket costs $10. The office is running a discount campaign: each group of 5 people is getting a discount, which is determined by the age of the youngest person in the group. You need to create a program that takes the ages of all 5 people as input and outputs the total price of the tickets. Sample Input: 55 28 15 38 63 Sample Output: 42.5

24th Jul 2022, 5:50 PM
Cojo Alex
Cojo Alex - avatar
7 Answers
+ 2
Yes but you need to show your some efforts.
24th Jul 2022, 6:04 PM
A͢J
A͢J - avatar
+ 2
Cojo Alex You are just taking inputs but not getting minimum age. You have to use another loop and store first value in a temporary variable Now compare temp. variable (minn) with next value of the array..if temp is greater than next value then store next value in temp. Now you have to get discounted amount so cout << 50.0 - 50.0 * temp / 100;
24th Jul 2022, 6:27 PM
A͢J
A͢J - avatar
+ 2
Cojo Alex I said store first value in a variable and compare with next value inside second loop. minn = ages[0]; Check this inside loop: if (minn < ages[i]) { minn = ages[i]; }
24th Jul 2022, 7:46 PM
A͢J
A͢J - avatar
+ 1
#include <iostream> using namespace std; int main() { int ages[5]; int minn; for (int i = 0; i < 5; ++i) { minn = ages[0]; cin >> ages[i]; if (minn < ages[i]) { minn = ages[i]; } } cout << (50.0 - 50.0*minn/100); return 0; } It works now, I have no errors but passes only 1 from 5 tests….
24th Jul 2022, 8:36 PM
Cojo Alex
Cojo Alex - avatar
0
I tried a lot. :) I am interested only in that line of code, to get the minimum from the inputs #include <iostream> using namespace std; int main() { int ages[5]; int minn; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } cout << (50 - minn/100); return 0; }
24th Jul 2022, 6:14 PM
Cojo Alex
Cojo Alex - avatar
0
Can you explain me what was wrong please?
25th Jul 2022, 5:39 AM
Cojo Alex
Cojo Alex - avatar
- 1
I tried something, but still wrong 😬 #include <iostream> using namespace std; int main() { int ages[5]; int minn; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } if (minn = ages[0]) { } else if (minn > ages++) { ages = minn; } cout << 50.0 - 50.0*minn/100; return 0; }
24th Jul 2022, 6:52 PM
Cojo Alex
Cojo Alex - avatar