Cheer Creator Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Cheer Creator Problem

I'm trying to solve the cheer creator problem in C language, but I'm still having 2 out of 5 test cases failing, and I have absolutely no idea what's wrong. Can anyone kindly check my code and point out the error? Thanks so much. https://www.sololearn.com/coach/20?ref=app

1st Feb 2020, 11:41 PM
Jim Ezesinachi
Jim Ezesinachi - avatar
6 Answers
+ 4
The loop is executed even if one of the if-statements before has already been triggered for all inputs other than zero, which should really not be the case.
2nd Feb 2020, 12:05 AM
Shadow
Shadow - avatar
+ 1
I've solved it guys. Thanks Shadow and Thống Nguyễn
4th Feb 2020, 11:10 AM
Jim Ezesinachi
Jim Ezesinachi - avatar
0
Here's my code #include <stdio.h> int main() { int yard; int j; scanf("%d", &yard); j=yard; if(j < 1) { printf("shh"); } if(j > 10) { printf("High Five"); } while(j=yard) { if(j>0 && j<11) { printf("Ra!"); yard--; j--; } } return 0; }
1st Feb 2020, 11:42 PM
Jim Ezesinachi
Jim Ezesinachi - avatar
0
Jim Ezesinachi first: you need to put the final if() out side the while()(or the while()'s stament always run): like this: if(){while(){}} Second: wrap your condition like this: while((j...))
2nd Feb 2020, 12:15 AM
Thống Nguyễn
Thống Nguyễn - avatar
0
Thanks guys. Lemme get to work
3rd Feb 2020, 11:03 AM
Jim Ezesinachi
Jim Ezesinachi - avatar
0
Please to help you!
4th Feb 2020, 11:26 AM
Thống Nguyễn
Thống Nguyễn - avatar