0

hi coders please can you help me to find the problem in solution this in c++

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 ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int min=ages[i]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if(ages[i]<min) { min =ages[i]; } float p=50 -(min/100); cout<<p<<endl;; } return 0; }

24th Mar 2022, 2:22 AM
Soneta
Soneta - avatar
3 Answers
+ 3
Soneta You have taken inputs 2 times. Remove second cin from second loop. Store first value to min then compare with next. int min = ages[0]; //this is right int min = ages[i] will give garbage value because of i = 5 and since there are only 5 elements so last index would be 4 so on index 5, garbage value will be store to min. You have to print outside the loop
24th Mar 2022, 2:50 AM
A͢J
A͢J - avatar
+ 2
Additionally, use a floating point literal for calculating percentage. Assuming 15 was value of <min> variable, min / 100 evaluates to 0 because both operands are integer. min / 100.0 evaluates to 0.15
24th Mar 2022, 4:15 AM
Ipang
+ 2
A͢J &Ipang I am grateful to you, thank you very much
24th Mar 2022, 2:18 PM
Soneta
Soneta - avatar