Float problem | Sololearn: Learn to code for FREE!

0

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 Giusti

9 Answers

New Answer

+5

<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?

+4

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.

+2

sorry the values ​​in scientific notation not in hex🤦‍♂️

+2

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; }

+1

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; }

+1

Ipang thank you very much. now I understand🙏

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

-1

It's the code project "ticket office" exercise of the learn c ++ section

-2

Float is working just like int