0

The output of the third input must be a float number

Even when I write float purchaseAmount it doesn't work https://www.sololearn.com/discuss/2889602/?ref=app

24th Sep 2021, 3:34 PM
Mbengue Mbor
Mbengue Mbor - avatar
3 Respostas
+ 5
I'm not sure whether you have trouble formatting the output of a decimal number, or calculating it (or maybe something else entirely). Some more information would be helpful, such as: - a code snippet detailing your problem - more information to what you are trying to do - a description of actual behaviour vs expected behaviour - maybe a certain input that triggers unwanted behaviour Linking your own question, on the other hand, is unfortunately not very helpful. EDIT: I discovered the post you were probably trying to refer to: https://www.sololearn.com/post/1297945/?ref=app While changing the definition to float purchaseAmount = 0; is a step in the correct direction, you also need to take into account that integer division yields an integer by default. In order to get a floating-point number, at least one operand must be one itself. Therefore, you also need to do something like the following in the loop: purchaseAmount = (totalPrice * 15) / 100.0;
24th Sep 2021, 3:43 PM
Shadow
Shadow - avatar
+ 1
For instance, getting an output as float you need to do "type casting" Although refering to the post i clearly see that everything is defined as integer and all other values {that's used for doing *,/,()} are integer, that's why you got your output as integer.
24th Sep 2021, 5:26 PM
Saurabh
Saurabh - avatar
0
The definition of the variables as integer is from sololearn
24th Sep 2021, 5:52 PM
Mbengue Mbor
Mbengue Mbor - avatar