Ticket office | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
21st Dec 2021, 5:16 PM
Lalala
Lalala - avatar
4 Answers
+ 2
Your formula is correct, but the code is a bit messed up. The following should be sufficient to produce the correct output: cout << (50 - (50 * min / 100.0)); See the last remark in my original answer as to why I included 100.0 instead of 100.
22nd Dec 2021, 12:20 PM
Shadow
Shadow - avatar
0
C++ usually does not initialize local variables for you, they contain whatever was stored in that memory before (commonly called garbage values). So, to summarize what the first three lines of your main function do: 1. Declare five uninitialized integer variables, which contain garbage values. 2. Declare an array of five integers and initialize its values to those of the variables, respectively. Now the array contains the same garbage values as the variables. 3. Accept five numbers from the input and store them in the variables. Given that you never update the array with the input values, from here on you still operate on garbage values when reading from the array. Switch lines 8 and 10 to fix this. There is the second issue that integer division yields another integer, i.e. your output does not calculate fractions correctly. At least one operand should be a floating-point type to produce a floating-point type as the result (e.g. 100.0 instead of 100).
21st Dec 2021, 7:34 PM
Shadow
Shadow - avatar
0
Shadow i switched 8and 10 but it's still not working I can't get half numbers
22nd Dec 2021, 11:56 AM
Lalala
Lalala - avatar
0
Shadow now i see thanx for your help ☺️☺️
22nd Dec 2021, 2:53 PM
Lalala
Lalala - avatar