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

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

21st Oct 2021, 1:29 PM
Mando
Mando - avatar
16 Answers
+ 3
Mando Be specific, What do you need help for?
21st Oct 2021, 1:35 PM
zexu knub
zexu knub - avatar
+ 2
You don't even need an array, just a for and two ifs. One for the first minimum and other to find the discount
22nd Oct 2021, 9:58 PM
José Francisco Macedo Calvillo
José Francisco Macedo Calvillo - avatar
+ 1
You don't need to sort the array – just iterate once and keep the minimum in a temporary variable.
21st Oct 2021, 2:16 PM
Lisa
Lisa - avatar
0
#include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } return 0; } What i got rn
21st Oct 2021, 1:30 PM
Mando
Mando - avatar
0
Its wants go take the youngest age of the person in the group and make their age a discount
21st Oct 2021, 1:36 PM
Mando
Mando - avatar
0
Mando You can perform sorting algorithm to determine the youngest one.
21st Oct 2021, 1:43 PM
zexu knub
zexu knub - avatar
0
How with what
21st Oct 2021, 1:43 PM
Mando
Mando - avatar
21st Oct 2021, 1:48 PM
zexu knub
zexu knub - avatar
0
Havent leanred bubble sort yet
21st Oct 2021, 1:49 PM
Mando
Mando - avatar
0
Mando This is the only efficient way i could tell right now. However if you wanna do it with the if/else condition then there's a way but it would be messy to look.
21st Oct 2021, 1:52 PM
zexu knub
zexu knub - avatar
0
Lisa how lol
21st Oct 2021, 2:16 PM
Mando
Mando - avatar
0
Iteration means "use a loop"
21st Oct 2021, 2:18 PM
Lisa
Lisa - avatar
0
Lisa still a bit confufussed on how to use a loop and use a temp varible to get the lowest number
21st Oct 2021, 2:21 PM
Mando
Mando - avatar
0
* int temp = 0; * loop over array: on each iteration check if the current array element is smaller than temp. If so, assign the current element value to temp * after the loop, temp is the minimum value of the array
21st Oct 2021, 2:25 PM
Lisa
Lisa - avatar
0
Mando compare each index with their next one & pick the smaller among them until you find the smallest one.
21st Oct 2021, 2:27 PM
zexu knub
zexu knub - avatar
0
Hello! Good evening! Can anyone help me to create sales management system using java? Thank you so much!
23rd Oct 2021, 12:41 PM
Nicole B.