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; }
3 ответов
+ 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;
}
+ 2
The variable 'gun' is supposed to be user defined.
+ 1
thank you so much, know it works.