You are working on a ticketing system. A ticket costs $10. The office is running a discount campaign: each group of 5 people i | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

You are working on a ticketing system. A ticket costs $10. The office is running a discount campaign: each group of 5 people i

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 The youngest age is 15, so the group gets a 15% discount from the total price, which is $50 - 15% = $42.5 #include<iostream> using namespace std; int main() { int i,a[5]; double j,small; for(i=0;i<5;i++) { cin>>a[i]; } if((a[0]<=a[1])&&(a[0]<=a[2])&&(a[0]<=a[3])&&(a[0]<=a[4])) { small =a[0]; } else if((a[1]<=a[0])&&(a[1]<=a[2])&&(a[1]<=a[3])&&(a[0]<=a[4])) { small=a[1]; } else if((a[2]<=a[1])&&(a[2]<=a[0])&&(a[2]<=a[3])&&(a[2]<=a[4])) { small=a[2]; } else small= a[3]; j=50-(small/2); cout<<j; return 0; } i solved it but hidden test case is failing So please guide

16th Sep 2021, 12:01 PM
B N Mallikarjuna
B N Mallikarjuna - avatar
3 Answers
+ 2
You're missing a condition for small = a[4];
16th Sep 2021, 12:59 PM
Simba
Simba - avatar
+ 2
B N Mallikarjuna If you write Hard Code logic you will never get success because inputs may be change for every case so how you can solve this problem just follow this steps: 1 - get youngest person, to do this store first value in a temporary variable and compare this value with each next value. You can use loop for this. 2 - after getting youngest person calculate discount on total price 3 - subtract this discount amount from total amount to get balance amount
16th Sep 2021, 12:27 PM
A͢J
A͢J - avatar
0
#include <iostream> #include <string> #include <climits> using namespace std; int main() { int ages[5]; double min = INT_MAX; double total; double discount; for (int i = 0; i < 5; i++) { cin >> ages[i]; if (ages[i] < min) min = ages[i]; } total = 50 * (min/100); discount = 50 - total; cout << discount; cout << endl; return 0; }
25th Aug 2022, 7:33 AM
the Monu
the Monu - avatar