0

Skee-Ball from Code Coach C++

Failure in test case 3. I thought reason was that is impossible to divide on 0. But I found solution. This code is working on my PC. include <iostream> using namespace std; int main() { int points, costintickets, ticket, guns; cin >> points; ticket = points / 12; cin >> costintickets; if (costintickets <= 0) { costintickets = 1; } guns = ticket / costintickets + 1; if (guns >= 2) { cout << "Buy it!"; } else { cout << "Try again"; } return 0; } Anyway failure is still there. What can be the case?

17th Feb 2020, 10:16 AM
Create A
Create A - avatar
4 Respuestas
+ 3
No. Of tickets = points/12 If no. Of tickets >= cost Print get it Else print try again thats all the logic you need. Dont overcomplicate the code.
17th Feb 2020, 11:54 AM
Salman Nazeer
Salman Nazeer - avatar
+ 2
Just remove the first if. Second if compare ticket >= costintickets
17th Feb 2020, 11:59 AM
Mihai Apostol
Mihai Apostol - avatar
+ 2
Thanks!
17th Feb 2020, 12:50 PM
Create A
Create A - avatar
+ 2
Create A You're welcome.
17th Feb 2020, 12:51 PM
Mihai Apostol
Mihai Apostol - avatar