+ 4

Problem in code coach

https://www.sololearn.com/coach/22?ref=app Why don't solve all cases? (copy-paste) 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) { uint pintures = Convert.ToUInt32( Console.ReadLine() ); if ( pintures > 0) { uint subtotal = pintures * 5 + 40; float tax = subtotal * 10 / 100; uint total = subtotal + Convert.ToUInt32( Math.Round( tax ) ); Console.WriteLine( total ); } else if ( pintures == 0) Console.WriteLine( 0 ); } } }

3rd Aug 2020, 1:07 PM
Kiwwi#
Kiwwi# - avatar
9 Respuestas
+ 6
Kiwwi I've just noticed that those if statements in the code are doing nothing much. A much cleaner version of your code: 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) { var pintures = Convert.ToInt32(Console.ReadLine()); var subtotal = pintures * 5 + 40.0; var tax = subtotal * 10 / 100; var total = subtotal + tax; Console.Write(((total-(int)(total))>=0.5f) ? Math.Ceiling(total) : Math.Floor(total)); } } }
3rd Aug 2020, 2:07 PM
minirkk
minirkk - avatar
+ 8
Kiwwi 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) { var pintures = Convert.ToInt32(Console.ReadLine()); if ( pintures > 0) { var subtotal = pintures * 5 + 40.0; var tax = subtotal * 10 / 100; var total = subtotal + tax; Console.Write(((total-(int)(total))>=0.5f) ? Math.Ceiling(total) : Math.Floor(total)); } else if ( pintures == 0) Console.WriteLine( 0 ); } } }
3rd Aug 2020, 1:28 PM
minirkk
minirkk - avatar
+ 6
Are you having problems with that problem, if yes then pls post your question so that we can figure it out
3rd Aug 2020, 1:10 PM
minirkk
minirkk - avatar
+ 5
hey Kiwwi the problem is with the rounding.
3rd Aug 2020, 1:35 PM
minirkk
minirkk - avatar
3rd Aug 2020, 1:48 PM
minirkk
minirkk - avatar
+ 3
You declared uint for pintures variable, so pintures always >= 0. If pintures <0, your programming will error.
3rd Aug 2020, 1:32 PM
Nguyễn Văn Sơn
Nguyễn Văn Sơn - avatar
+ 1
Don't solve all evaluation cases, but think its the correct solution, so I put it here to others can check (copy-paste on the link to review it)
3rd Aug 2020, 1:12 PM
Kiwwi#
Kiwwi# - avatar
+ 1
Nguyễn Văn Sơn yes, but before did with normal int and the same problem
3rd Aug 2020, 1:33 PM
Kiwwi#
Kiwwi# - avatar
+ 1
Yes I see that now, but don't know ceiling and floor yet, what they do?
3rd Aug 2020, 1:37 PM
Kiwwi#
Kiwwi# - avatar