0
Ticket office
What's wrong with my code?? Please help 🥺🥺🥺🥺 https://code.sololearn.com/c2adfBOEd0m8/?ref=app https://code.sololearn.com/c2adfBOEd0m8/?ref=app
4 Réponses
+ 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.
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).
0
Shadow i switched 8and 10 but it's still not working
I can't get half numbers
0
Shadow now i see thanx for your help ☺️☺️