0

[SOLVED] Wrong C# 78.2 exercise evaluation?

In C# course, Stack exercise, don't know why it doesn't works: using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { var evenNums = new Stack<int>(); evenNums.Push(4); evenNums.Push(8); evenNums.Push(6); int num = Convert.ToInt32(Console.ReadLine()); evenNums.Push(num); Console.WriteLine("Checking the last number: " + num); if ( num % 2 != 0 ) Console.WriteLine(

quot;{evenNums.Pop()}: Removed"); for (int i = 0; i < evenNums.Count; i++) Console.Write(
quot;{evenNums.Pop()} "); } } }

30th Dec 2020, 5:31 AM
Kiwwi#
Kiwwi# - avatar
2 Answers
+ 6
Kiwwi# In loop no need to remove again. You just have to print the value. if ( num % 2 != 0 ) Console.WriteLine(
quot;{evenNums.Pop()}: Removed"); foreach (int i in evenNums) Console.Write(i + " ");
30th Dec 2020, 6:02 AM
A͢J
A͢J - avatar
+ 1
I Am Groot ! now understand, it was shortening it on the fly so doesn't match all
30th Dec 2020, 1:02 PM
Kiwwi#
Kiwwi# - avatar