Help over cheer creator challenge. 4/5 cases right | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help over cheer creator challenge. 4/5 cases right

Task Given the number of yards that your team moved forward, output either 'High Five' (for over 10), 'shh' (for <1), or a string that has a 'Ra!' for every yard that they gained. Problem: When I put an input of 1 it prints out Ra! 9 times, and I need it to only print out once. I don’t know how to fix that. My code: https://code.sololearn.com/cIOc3vIie4Q9/?ref=app

18th Dec 2021, 4:31 AM
Saja
4 Answers
+ 2
You are using loop logic wrong. Use while(i>0) and do i-- in loop. You are doing while(i<10) I++ it will print untill I becomes 10 and we only have to print Ra! i times
18th Dec 2021, 5:11 AM
Sagar Sharma
Sagar Sharma - avatar
+ 1
#include <stdio.h> int main() { int i; scanf("%d", &i); if (i > 10){ printf("High Five"); } else if (i < 1){ printf("%s", "shh"); } else if (i<10){ while(i>0){ printf("Ra!"); i--; } } return 0; }
18th Dec 2021, 5:13 AM
Sagar Sharma
Sagar Sharma - avatar
+ 1
i=1 while(i<10){ printf("Ra!"); i++; } 👇 1<10 => true "Ra!" i++ 2<10 => true "Ra!" i++ ... Think about what you need to do so that i corresponds to the number of repetitions.
18th Dec 2021, 5:19 AM
Solo
Solo - avatar
18th Dec 2021, 5:42 AM
Saja