0

Please help me to code

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

2nd Sep 2022, 5:50 PM
Arjun Singh
Arjun Singh - avatar
3 Answers
+ 3
Won't work because edit: Oh. No. You are taking input and comparing with min in same loop. It is works like min = ages[i] ; both same values now then if( min < ages [I] ) never true. Because both values are same. so you don't get any output. First need to find minimum value then find discount so discount print should be after and out side loop... int min ; min=ages[i]; // both same hence, min<ages[I] always false. first take all inputs Take array first value like min = ages[0] ; then by another loop, Next, you need to find is their any value mininmum than ages[0] so by a loop find that min value if exist. // this statement won't work. // if (min<ages[i] ) use min > ages[i] then change min = ages[i]; you will get minimum then calculate cout<<50-min*50/100; // take 100.0 , not 100 Definitely, I want to say, you need to understand some more by revising lessons before attempting this challenges.. hope it helps.... Happy learning...
2nd Sep 2022, 6:18 PM
Jayakrishna šŸ‡®šŸ‡³
0
#include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; //your code goes here int min ; min=ages[i]; if (min<ages[i] ) cout<<50-min*50/100; } return 0; }
2nd Sep 2022, 5:53 PM
Arjun Singh
Arjun Singh - avatar
0
This isn't working
2nd Sep 2022, 5:54 PM
Arjun Singh
Arjun Singh - avatar