0

Please help me to solve this error

You are playing a game at your local arcade, and you receive 1 ticket from the machine for every 12 points that you score. You want to purchase a squirt gun with your tickets. Given your score, and the price of the squirt gun (in tickets) are you able to buy it? Task Evaluate whether or not you have scored high enough to earn enough tickets to purchase the squirt gun at the arcade. Input Format The first input is an integer value that represents the points that you scored playing, and the second input is an integer value that represents the cost of the squirt gun (in tickets). Output Format A string that say 'Buy it!' if you will have enough tickets, or a string that says 'Try again' if you will not. Sample Input 500 40 Sample Output Buy it! #include <stdio.h> int main() { int score; int cost; int ticket; ticket=score/12; if (ticket >cost){ printf("Buy it!"); } else{ printf ("Try again"); } return 0; }

3rd May 2021, 5:04 PM
Priyanka K
Priyanka K - avatar
5 Respuestas
+ 3
See It is not always greater, someone it is equal also so when ticket==cost. Add this condition and try once again
3rd May 2021, 5:29 PM
Atul [Inactive]
+ 2
Michał Doruch But how it is showing true for 1st case
3rd May 2021, 5:39 PM
Atul [Inactive]
+ 1
Assign values to your variables before using them. Use scanf() function to get user input. Btw your condition should be true not only when ticket>cost, but when it's equal too (ticket>=cost)
3rd May 2021, 5:35 PM
Michal Doruch
+ 1
Atul cuz these variables hold gargabe values, when you divide garbage/12 (for example 627473/12) it will return true, as the result is not equal to 0. Only global/static variables are 0 by default (I think they are)
3rd May 2021, 5:41 PM
Michal Doruch
0
Okk i will try
4th May 2021, 5:13 AM
Priyanka K
Priyanka K - avatar