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

Code Coach Cheer Creator question

Hey y’all, I’m very new to coding and I was doing some of the projects in Code Coach to practice. I did the Cheer Creator project and thought I had it figured out but the result didn’t pass all the test cases. Unfortunately the test cases that the code didn’t pass were hidden. So I copied the code and pasted it into the code playground to see and check the output myself and I’m confused because it seems to be working properly. I tried a variety of inputs but it seems to work just fine. So I was wondering if anyone would be familiar with the project mentioned and might be able to spot the issue for me? Also I realize my code may not be the most efficient way to achieve its result. I just really wanted to figure it out without looking it up completely for once so I believe I took a longer route lol. But I am interested in learning a more efficient way to code this project if anyone has any input on that or any tips at all really. Thank you! { static void Main(string[] args) { int yards; yards = Convert.ToInt32(Console.ReadLine()); switch (yards) { case 0: Console.WriteLine("shh"); break; case 1: Console.WriteLine("Ra!"); break; case 2: Console.WriteLine("Ra!Ra!"); break; case 3: Console.WriteLine("Ra!Ra!Ra!"); break; case 4: Console.WriteLine("Ra!Ra!Ra!Ra!"); break; case 5: Console.WriteLine("Ra!Ra!Ra!Ra!Ra!"); break; case 6: Console.WriteLine("Ra!Ra!Ra!Ra!Ra!Ra!"); break; case 7: Console.WriteLine("Ra!Ra!Ra!Ra!Ra!Ra!Ra!"); break; case 8: Console.WriteLine("Ra!Ra!Ra!Ra!Ra!Ra!Ra!Ra!"); break; case 9: Console.WriteLine("Ra!Ra!Ra!Ra!Ra!Ra!Ra!Ra!Ra!"); break; case 10: Console.WriteLine("High five!"); break; default: Console.WriteLine("High five!"); break; } } } }

21st Dec 2020, 2:41 PM
Tee
Tee - avatar
5 Answers
+ 5
The first problem is that for a distance of ten yards, you are still supposed to display "Ra!" ten times, and "High five!" only if the team moved more than ten yards. However, you also need to keep in mind what happens if your team moves backwards, i.e. a negative distance is entered. Using if-conditions and a loop for the correct amount of "Ra!"s to display could go a long way to shorten your code.
21st Dec 2020, 2:53 PM
Shadow
Shadow - avatar
+ 2
MrDevEzeoke The problem is that the first two conditions both match an input greater than ten, in which case the first one is executed and "Ra!" is displayed instead of "High Five". You can add another condition to limit the first statement to inputs smaller or equal to ten via the AND operator, or switch the order of the statements to fix it.
1st Jan 2021, 11:35 AM
Shadow
Shadow - avatar
+ 1
Ahh thank you so much! I’ll read the directions more thourougly next time and im going to review if conditions and loops again. Appreciate your help
21st Dec 2020, 3:08 PM
Tee
Tee - avatar
0
https://code.sololearn.com/c6y80Iph3moH/?ref=app Shadow Could you also help me with this. Idk why is it not working to for Test Case 3.
1st Jan 2021, 9:22 AM
Kanji-50
Kanji-50 - avatar
0
Shadow Thank you.
1st Jan 2021, 11:36 AM
Kanji-50
Kanji-50 - avatar