0

# Izzy the iguana code coach

Only the second test case fails and I donâ€™t know how to fix it. You need to get 10 points and heâ€™ll come down, else he stays. Hereâ€™s my code: int b = 0; string[] a = Console.ReadLine().Split(' '); if(a.Contains("Cheeseburger")){ b+=0; } if(a.Contains("Lettuce")){ b+=5; } if(a.Contains("Carrot")){ b+=4; } if(a.Contains("Mango")){ b+=9; } if(b >= 10){ Console.WriteLine("Come on Down!"); } else if(b < 10){ Console.WriteLine("Time to wait");

1st Dec 2022, 5:41 PM
Nikola Markov
+ 4
In the if-else part, you need to change "a" to "c", e.g. c.Contains("Mango")
1st Dec 2022, 7:55 PM
Lisa
+ 6
You could use a for-loop or a foreach-loop to iterate the string array. On each iteration, check which food it is and add the corresponding number to "b".
1st Dec 2022, 7:28 PM
Lisa
+ 4
If the input contains "Carrots" 3 times, we need to thr number 3 times. Your code would only add it once.
1st Dec 2022, 7:16 PM
Lisa
0
Ok, but how should i check if there is a word multiple times?
1st Dec 2022, 7:24 PM
Nikola Markov
0
Ok thank you!!!
1st Dec 2022, 7:30 PM
Nikola Markov
0
Thanks for the help, but now it fails only the fourth case, which was correct before.
1st Dec 2022, 7:50 PM
Nikola Markov
0
Heres the new code with a forach loop: int b = 0; string[] a = Console.ReadLine().Split(' '); foreach(string c in a){ if(a.Contains("Cheeseburger")){ b+=0; } if(a.Contains("Lettuce")){ b+=5; } if(a.Contains("Carrot")){ b+=4; } if(a.Contains("Mango")){ b+=9; } } if(b >= 10){ Console.WriteLine("Come on Down!"); } else if(b < 10){ Console.WriteLine("Time to wait");
1st Dec 2022, 7:50 PM
Nikola Markov
0
Thank you!
1st Dec 2022, 8:13 PM
Nikola Markov