+ 1

Skee ball 1 from 5 tests not passed

Whats problem please? Listing of c++ code below: #include <iostream> using namespace std; int main() { int scores, price, bool_1; cin >> scores >> price; bool_1 = scores / (12 * price); if (bool_1 >0) cout << "Buy it!"; else cout << "Try again"; return 0; }

17th Feb 2020, 7:56 PM
Сергей Румянцев
Сергей Румянцев - avatar
5 odpowiedzi
+ 5
Your problem is that scores / (12 * price) will always be greater than 0. instead try changing the condition to: if((price * 12) <= scores)
17th Feb 2020, 8:22 PM
Kylie
Kylie - avatar
+ 1
Change the condition in 'if' statement, bool_1 is always greater than 0 so it always print "By it". Try this : #include <iostream> using namespace std; int main() { int scores, price, bool_1; cin >> scores >> price; bool_1 = scores / (12 * price); if (bool_1 >= 1) cout << "Buy it!"; else cout << "Try again"; return 0; }
17th Feb 2020, 8:53 PM
Rafik Abdelhak Nadir
Rafik Abdelhak Nadir - avatar
+ 1
Thank's Kylie! Code is working.
17th Feb 2020, 9:22 PM
Сергей Румянцев
Сергей Румянцев - avatar
+ 1
Thank you Maharnab Saikia! I was stumped after trying to change it up a few different ways for C. I had if (tickets > cost) { printf("%s", buy); return 0; After seeing your comment and adding the = character it worked. if (tickets >= cost) { printf("%s", buy); return 0; It passed the one. Thanks you!
18th May 2021, 2:46 AM
Earl
0
Сергей Румянцев Your code does not work for price = 0. Am I right tht only one test case fails?
17th Feb 2020, 8:23 PM
Denise Roßberg
Denise Roßberg - avatar