Stack & Queue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Stack & Queue

The program you are given defines the evenNums stack and pushes 3 even numbers (6, 8 and 4) onto it. The 4th number is taken from the user and also pushed. But we need to check whether it is also an even number. Complete the program to perform that check process, and if the last pushed number N isn't even, remove it from stack and output "N: Removed" (see sample output). At the end, output all the elements of the stack, separated by spaces. Sample Input 1 Sample Output Checking the last number: 1 1: Removed 6 8 4 Anyone take it a look my code please, it works for me but it does not pass the all test. any suggest please https://code.sololearn.com/ca13a0A23a21

26th Jun 2021, 9:28 PM
JRAMAHES
JRAMAHES - avatar
1 Answer
+ 1
I see what's causing the issue. You need to add a space right after the colon in line 19. So Console.WriteLine("Checking the last number:space" + num). Then again on line 24 Console.WriteLine(num + ":spaceRemoved"). I would also suggest switching your lines 24 and 25 so that the statement is printed after its removed from the stack. You should be good!
29th Jun 2021, 1:25 PM
BlueFire1712
BlueFire1712 - avatar