Why not work? How i can resolve this, I'm noob sorry | Sololearn: Learn to code for FREE!

+1

Why not work? How i can resolve this, I'm noob sorry

https://www.sololearn.com/coach/22?ref=app cost = 40 ccolor = 5 ncolor = gets.to_i subtotal = cost + (ccolor * ncolor) totaltax = subtotal / 10 total = subtotal + totaltax puts total Why not work? How i can resolve this, I'm noob sorry

1/28/2020 2:32:22 PM

cono nico coco

15 Answers

New Answer

+2

No prob Richard Alfonzo I could have given you the code but I wanted you to do it yourself 👍

+7

As the task description says, the result shown as output should be rounded UP to the nearest whole number. The method in ruby for this is ".ceil".

+7

Python: clc = int(input()) cst = round(((clc * 5.0)+40.0)*1.1) print(cst) Ruby: clc = gets.to_i cst = (((clc * 5.0)+40.0)*1.1).round() puts cst

+7

HonFu Lothar I wouldn’t be so categorical about these codes of the trainer ... the fact that the description of the problem doesn’t quite accurately describe it can be considered a plus that increases the complexity of the search for the required solution a little ... in real life it’s a rarity to absolutely clearly and correctly describe the task ... usually if there is such a description, then the problem has already been solved. yes, and unfortunately, this section is no longer developing..🤔

+6

An other issue is the division in your code. In ruby the following results are given: puts 5 / 10, "\n" # returns 0 puts 5 / 10.0, "\n" # returns 0.5 To get a float you have to divide by "10.0", and later on you have to use the .ceil method to get the result.

+3

Lothar yes , that's what I hinted in my first comment

+2

I don't know Ruby well. Does this come out as a float? They only want two decimal places in the output then.

+2

Have you tested your code with different manual inputs? If not, do that. See if it comes out like a price should, with decimals, but only two.

+2

I have achieved it, with round and abs and a small change in the formula, thank you very much for the help :)

+2

You're right, Lothar. All these code coach posts, it's starting to become a huge blur. 🥴

+1

Richard Alfonzo you have to use round() try and come back edit hint : cost 40.00. Each color of paint that you buy is an additional 5.00

+1

I try with round and abs and when I test the cases, I only exceed 2 of the 5, I don't know why, I also can't see which is the wrong entry :(

0

"Output Format A number that represents the cost of your purchase rounded up to the nearest whole number." I think the problem is the result has to be an integer, I don't know how to convert the output to an integer or that the input is an integer

0

Any body is to learn with me

-2

No problem Richard We could have given you the code but we want you to do it yourself 😎