Paint costs C# one test fail | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Paint costs C# one test fail

I have code: int colors = Convert.ToInt32(Console.ReadLine()); double dcost = 40.00 + (colors * 5.00)+((40.00 + (colors * 5.00))*0.10); Console.WriteLine(dcost); dcost = Math.Round(dcost); Console.WriteLine(dcost); Before and used only int and tax as double and next Convert.ToInt32 and have the same problem int colors = Convert.ToInt32(Console.ReadLine()); int costs = 40 + (colors * 5); double tax = costs * 0.10; int t = Convert.ToInt32(tax); int totalCost = costs + t; Console.WriteLine(totalCost); I check few numbers and rounding seems to work well :/

18th Jul 2020, 6:03 PM
Mr Wolfy
Mr Wolfy - avatar
2 Answers
+ 6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { double total_cost; double cost,tax; int numberOfcolor = int.Parse(Console.ReadLine()); cost=(numberOfcolor*5)+40; tax=cost/10; total_cost=Math.Ceiling(tax)+cost; Console.WriteLine(total_cost); } } }
18th Jul 2020, 6:11 PM
Orchiiik
Orchiiik - avatar
0
Oh okey i changed Math.Round on Math.Ceiling and everything is pass, thanks
18th Jul 2020, 6:18 PM
Mr Wolfy
Mr Wolfy - avatar