# Float problem

I have a problem with float values😭😭😭 ... sometimes it returns me hex values other times not. Can anyone help me please? thank you very much

2/5/2022 8:17:51 PM

Giuseppe Giusti9 Answers

New Answer<ages> is an unitialized local variable which may contain garbage value. So assigning <ages>[ 0 ] to <min> is risky. Also, <ages> is an array of `int` so updates to <min> (a `float` type) isn't all too safe without type casting, because of different ways of how those types store values in memory. What was the task again?

Some of us would like to know what language you had in mind. We are also lacking knowledge of how the code was instructed to format the output. Kindly share the code so we may properly recommend solutions.

Giuseppe Giusti, Look at this, I added a bit of comment explaining the code flow. #include <iostream> using namespace std; int main() { int ages[5], min; float price = 50.0; cin >> ages[0]; // read first person's age min = ages[0]; // assume it as <min> for (int i = 1; i < 5; ++i) // read ages for remaining 4 persons { cin >> ages[i]; if (min > ages[i]) { min = ages[i]; } } float sum = price - price * min / 100.0; // calculate discount cout << sum; return 0; }

Sorry the language is c++ #include <iostream> using namespace std; int main() { int ages[5]; float price = 50; float min = ages[0]; float sum = 0.0; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if (min > ages[i]) { min = ages[i];} } //your code goes here sum = price - price * min / 100; cout << sum; return 0; }

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