Free webinar! How to Make Generative AI Work for You
Get my free ticket+ 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
17 Answers
+ 3
Mando Be specific, What do you need help for?
+ 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
+ 1
You don't need to sort the array – just iterate once and keep the minimum in a temporary variable.
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
0
Its wants go take the youngest age of the person in the group and make their age a discount
0
Mando You can perform sorting algorithm to determine the youngest one.
0
How with what
0
Mando bullble sort : https://www.programiz.com/dsa/bubble-sort
0
Havent leanred bubble sort yet
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.
0
Lisa how lol
0
Iteration means "use a loop"
0
Lisa still a bit confufussed on how to use a loop and use a temp varible to get the lowest number
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
0
Mando compare each index with their next one & pick the smaller among them until you find the smallest one.
0
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int ages[5];
for (int i = 0; i < 5; ++i) {
std::cin >> ages[i];
}
//your code goes here
const double ticket_cost = 10;
int youngest = ages[0];
for (int i = 0; i < 5; i++) {
// 0 > 55
if (youngest > ages[i]) {
youngest = ages[i];
}
}
int peoples = (sizeof(ages) / sizeof(int));
double price = peoples * ticket_cost;
double discount = (price - ((price*youngest / 100)));
std::cout << std::setprecision(3) << discount << std::endl;
return 0;
}
0
Hello! Good evening! Can anyone help me to create sales management system using java? Thank you so much!