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");
8 odpowiedzi
+ 4
In the if-else part, you need to change "a" to "c", e.g.
c.Contains("Mango")
+ 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".
+ 4
If the input contains "Carrots" 3 times, we need to thr number 3 times.
Your code would only add it once.
0
Ok, but how should i check if there is a word multiple times?
0
Ok thank you!!!
0
Thanks for the help, but now it fails only the fourth case, which was correct before.
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");
0
Thank you!