Izzy The Iguana, C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Izzy The Iguana, C#

I could not find help for this in C#. string snacks = Console.ReadLine(); snack = snacks.Split(); int points = 0; now what? you have to add 5 points for lettuce, carrot is 4, mango is 9, cheeseburg is 0. foreach loop where points+=snacktype but obviously i am not sure. do i use snacks or snack based on the split?

16th Mar 2023, 7:29 PM
Breanna Thompson
Breanna Thompson - avatar
3 Answers
+ 6
Breanna Thompson , the beginning of the code should be: ... string snacks = Console.ReadLine(); string[] snack = snacks.Split(); now you have an array of strings named *snack* that you can iterate over with a *foreach* loop.
16th Mar 2023, 8:31 PM
Lothar
Lothar - avatar
+ 2
Can you share link to your tryout code in post Description? need to see it first before saying something. Basically you use a loop to walk the <snack> string array through. Checking whether any of the elements were either one of these as you go "Lettuce" on which you add 5 to <points> "Carrot" on which you add 4 to <points> Or "Mango" on which you add 9 to <points>. Once you walked through the <snack> array, use `if...else` conditional to assess whether <points> was enough to persuade it down, and what to output. Careful with outputs, one small difference to the task requirement can fail you .,.. (Edited)
16th Mar 2023, 7:50 PM
Ipang
+ 2
You can use if statements in the loop: if the current item equals "Carrot" you add the carrot points, and so on.
16th Mar 2023, 7:51 PM
Lisa
Lisa - avatar