+ 1

Skee Ball in C# test case #3

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) { int score = Convert.ToInt32(Console.ReadLine()); int price = Convert.ToInt32(Console.ReadLine()); if (score == 0 || price == 0) { Console.WriteLine("Try again"); } else if (score / price >= 12) { Console.WriteLine("Buy it!"); } else { Console.WriteLine("Try again"); } } } } Why is case 3 failing? I can't see the input because I'm not a pro user. I thought it would have been inputting 0.

18th Dec 2021, 12:18 PM
Alain Sauve
5 Respuestas
+ 1
Alain Sauve First: Nobody can see hidden cases. Even pro users. Next: I did some Tests. You are right. Case 3 is for price = 0. You mistake: One missing else statement after the first if condition. Here I have added it: 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) { int score = Convert.ToInt32(Console.ReadLine()); int price = Convert.ToInt32(Console.ReadLine()); if (price == 0) { Console.WriteLine("Buy it!"); } else { if (score / price >= 12) { Console.WriteLine("Buy it!"); } else { Console.WriteLine("Try again"); } } } } }
18th Dec 2021, 1:24 PM
Coding Cat
Coding Cat - avatar
+ 2
// try this int score = Convert.ToInt32(Console.ReadLine()); int price = Convert.ToInt32(Console.ReadLine()); if(score/12 >= price) Console.WriteLine("Buy it!"); else Console.WriteLine("Try again");
18th Dec 2021, 12:49 PM
SoloProg
SoloProg - avatar
+ 1
That didn't change anything. I still got the same fail on test case #3. I wish I could see the input to find out what the heck is going on there.
18th Dec 2021, 12:56 PM
Alain Sauve
+ 1
Coding Santa I appreciate the help :) I eventually figured it out with this code. I realized that if the cost of the damn gun is 0 I should be buying it, not running away from a killer deal hahah 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) { int score = Convert.ToInt32(Console.ReadLine()); int cost = Convert.ToInt32(Console.ReadLine()); int tickets = score / 12; if (tickets >= cost) { Console.WriteLine("Buy it!"); } else { Console.WriteLine("Try again"); } } } }
18th Dec 2021, 1:27 PM
Alain Sauve
0
Alain Sauve I solved it the same passed all the tests
20th Dec 2021, 8:27 AM
Mohammed Alimam
Mohammed Alimam - avatar