Snap, Crackle and Pop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Snap, Crackle and Pop

int[] numbers = new int[6]; int count = 0; while (count < 6) { numbers[count] = Convert.ToInt32(Console.ReadLine()); count++; } foreach (int i in numbers) { if (i % 3 == 0) { Console.Write("Pop" + " "); } else if (i % 3 != 0 && i % 2 != 0) { Console.Write("Snap" + " "); } else if (i % 3 != 0 && i % 2 == 0) { Console.Write("Crackle" + " "); } }

3rd Nov 2021, 1:58 PM
Роман Жигунов
Роман Жигунов - avatar
4 Answers
+ 4
Роман Жигунов , first of all, please post complete codes in future - thanks. the issue is, that the code prints strings + a space. this is necessary for all outputs, except the last one. what you can do is to collect all outputs in a string variable. it will also have the unnecessary last space. but this can be solved during the output like: Console.WriteLine(output.Trim()); Trim() removes leading and trailing spaces. happy coding!
3rd Nov 2021, 6:52 PM
Lothar
Lothar - avatar
+ 4
4th Nov 2021, 9:33 AM
Lothar
Lothar - avatar
+ 1
in the conditions of the problem, it is required to output sounds in one line, separated by a space, did not understand your explanation, show an example
4th Nov 2021, 5:34 AM
Роман Жигунов
Роман Жигунов - avatar
+ 1
aaaa) I understand now, thanks)
4th Nov 2021, 12:16 PM
Роман Жигунов
Роман Жигунов - avatar