Sololearn C++ Ticket Office Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Sololearn C++ Ticket Office Problem

Here's the question: 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 This is my attempt #include <iostream> using namespace std; int main() { cout<<"Started >"; int ages[5]; for (int i = 0; i < 5; i++) { cin >> ages[i]; } //your code goes here int smallest = ages[0]; for (int x = 0; x < 5; x++) { /* code */ x=ages[x]; if (smallest>ages[x]) { /* code */ smallest=ages[x]; } } cout<<50-50*smallest/100<<endl; return 0; }

2nd Feb 2021, 4:39 PM
Satvik Gaikwad
Satvik Gaikwad - avatar
6 Answers
+ 1
What is x=ages[x] inside for loop doing there?
2nd Feb 2021, 4:56 PM
Abhay
Abhay - avatar
+ 4
Thanks I have changed few things #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 smallest = ages[0]; for (int x = 0; x < 5; x++) { /* code */ int y=ages[x]; if (smallest>y) { /* code */ smallest=ages[x]; } } float minus=0.5*smallest; int total=50; cout<<total-minus; return 0; }
3rd Feb 2021, 2:03 AM
Satvik Gaikwad
Satvik Gaikwad - avatar
+ 2
Everything looks good only as Abhay said remove x=ages[x], also use brackets for calculations just to avoid any error.
2nd Feb 2021, 5:02 PM
Sanjyot21
Sanjyot21 - avatar
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 smallest = ages[0]; for (int x = 0; x < 5; x++) { /* code */ int y=ages[x]; if (smallest>y) { /* code */ smallest=ages[x]; } } float minus=0.5*smallest; int total=50; cout<<total-minus; return 0; }
22nd Apr 2021, 4:28 PM
Marcela Bueno
Marcela Bueno - avatar
0
me sale que tu codigo esta mal
24th May 2021, 9:21 PM
Yordan
- 1
Why the calculation is never right if i write "float minus=smallest/100*50;" ??? Please help im a beginner
19th Jun 2022, 9:41 PM
Adam Alfakhri
Adam Alfakhri - avatar