0

Why I have this code wrong? (C++)

I am trying to solve skee ball problem in C++. I have every of the cases right except the 3 one, and I don’t know why. If anyone could help me I would be totally grateful. Thanks #include <iostream> using namespace std; int main() { int tickets; int points; int gun; cin>>points; tickets=(points/12); gun=40; if(tickets>=40) { cout<<"Buy it!"; } else { cout<<"Try again"; } return 0; }

27th Apr 2020, 1:02 PM
Dan Delgado
Dan Delgado - avatar
3 Answers
+ 4
In skee ball problem we have to take 2 inputs and you have taken only one. "gun" variable must be taken as input and in the if statement condition it should be "tickets>=gun" After making some changes your code will be as follows; #include <iostream> using namespace std; int main() { int tickets, points, gun; cin>>points; cin>>gun; tickets=points/12; if(tickets>=gun) { cout<<"Buy it!"; } else { cout<<"Try again"; } return 0; }
27th Apr 2020, 1:15 PM
...
+ 2
The variable 'gun' is supposed to be user defined.
27th Apr 2020, 1:42 PM
Justus
Justus - avatar
+ 1
thank you so much, know it works.
27th Apr 2020, 2:46 PM
Dan Delgado
Dan Delgado - avatar