Ticket Office Run | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ticket Office Run

Ticket Office 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 Here is other's code: #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } double m; double p; m = ages[0]; for (int x = 1; x < 5; ++x) { if ( m > ages[x]) { m = ages[x]; } } p = 50 - (50*m/100); cout << p << endl; return 0; } I don't really get the part start from double m and p. Why m = ages[0] ( is this means that it don't have any elements in this arrays ?) why int x equal to 1 ? what does the ( ( m > ages[x]) { m = ages[x]; } means ?

9th Jun 2021, 3:32 PM
DAYU
DAYU - avatar
13 Answers
+ 2
Big Fish i thinks the logic is wrong but I will Still explain u what is happening here. part 1 : Data Input from user to an array "ages[5]" using a for loop eg. ages[5] = {23,17,65,47,15} part 2 : Finding the Youngest aged person. explained :- a. They declared "m" and "p" variable where m means minimum age and p means price of tickets b. They give the value of first element of ages array (which is the age of first person ) to m variable c. then they run a loop to find the smallest element of array ( minimum aged person ) or discount % d. as we know the array element starts from 0 and we already stored the value of 0th element in m variable so they started the loop from second element using int i = 1 part 3 : Caluclation logics to get price with discount and print the price with cout
9th Jun 2021, 3:38 PM
Abhay Bro
Abhay Bro - avatar
+ 2
Big Fish this is not ur fault I means you are just a beginner that is not a big deal U just need to practise, I know you had paid attention to lesson but this things ( having bugs and unable to catch up the code fastly ) happens with every beginner even with me also about 3 years ago when I am in School. So Just keep practicing.😁
9th Jun 2021, 3:56 PM
Abhay Bro
Abhay Bro - avatar
+ 1
Thanks guys! yah I think I need to do recap again :(
9th Jun 2021, 3:43 PM
DAYU
DAYU - avatar
+ 1
Abhay Bro Logic is absolutely right. There is no any issue.
9th Jun 2021, 3:57 PM
A͢J
A͢J - avatar
9th Jun 2021, 4:00 PM
Abhay Bro
Abhay Bro - avatar
+ 1
:"D Thanks QQQQ !! I will practice as more as I can
10th Jun 2021, 5:21 AM
DAYU
DAYU - avatar
0
Big Fish ages[0] means we are getting 1st element to compare with next elements in an array to get youngest age. We have started x with 1 because we have to compare 1st element with next elements so doesn't make sense to compare 1st element with 1st element.
9th Jun 2021, 3:37 PM
A͢J
A͢J - avatar
0
For that you should have paid attention in lessons before this module question. This specific part is covert here 👇 https://www.sololearn.com/learning/1625/
9th Jun 2021, 3:38 PM
Arsenic
Arsenic - avatar
0
Ya I pay attention but somehow brain stuck btw thanks!
9th Jun 2021, 3:43 PM
DAYU
DAYU - avatar
0
Ticket Office Why test case 3? I need an answer for this? include <iostream> using namespace std; int main(){ int ages[5]; for (int i + 0; <5; i++){ cin>>ages[i]; } int a= ages[0]; int b= ages[1]; int c= ages[2]; int d= ages[3]; int e= ages[4]; if ((a<b)&&(a<c)&&(a<d)&&(a<e)){ float w=a; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((b<a)&&(b<c)&&(b<d)&&(b<e)){ float w=b; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((c<b)&&(c<a)&&(c<d)&&(c<e)){ float w=c; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((d<b)&&(d<c)&&(d<a)&&(d<e)){ float w=d; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((e<b)&&(e<c)&&(e<d)&&(e<a)){ float w=e; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } return 0; }
24th Oct 2021, 7:34 PM
Swapnil Chavan
Swapnil Chavan - avatar
0
Ticket Office Why test case 3? I need an answer for this? include <iostream> using namespace std; int main(){ int ages[5]; for (int i + 0; <5; i++){ cin>>ages[i]; } int a= ages[0]; int b= ages[1]; int c= ages[2]; int d= ages[3]; int e= ages[4]; if ((a<b)&&(a<c)&&(a<d)&&(a<e)){ float w=a; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((b<a)&&(b<c)&&(b<d)&&(b<e)){ float w=b; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((c<b)&&(c<a)&&(c<d)&&(c<e)){ float w=c; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((d<b)&&(d<c)&&(d<a)&&(d<e)){ float w=d; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } if ((e<b)&&(e<c)&&(e<d)&&(e<a)){ float w=e; float p=(w/100)*50; float y=50-p; cout<<y<<endl; } return 0; }
24th Oct 2021, 7:35 PM
Swapnil Chavan
Swapnil Chavan - avatar
0
#include <iostream> using namespace std; int main() { int ages[5]; int total = 50; float final, discount; for (int i = 0; i < 5; i++) { cin >> ages[i]; } int min = ages[0]; for (int i = 0; i < 5; i++) { if (ages[i] < min) min = ages[i]; } discount =(min * 0.01) * total; final = total - discount; cout << final; return 0; }
24th Oct 2021, 7:37 PM
Swapnil Chavan
Swapnil Chavan - avatar
0
Hi guys! My code variant. #include <iostream> using namespace std; int main() { int ages[5]; int min_age; min_age = ages[0]; float t=50.0; float price; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if(ages[i] < min_age) { min_age = ages[i]; } } price=t-((t*min_age)/100); cout<<"Price with discount "<< price<<endl; return 0; }
7th May 2022, 3:49 PM
Oleksandr Lavrenchuk
Oleksandr Lavrenchuk - avatar