To summarize I was trying to make a number guessing game where two players take turns guessing the random number. The limit the random number can be, like it can’t go over a certain number, is also determined by the users. I was trying to add a feature where if you type in 789 for your guess it tells you the numbers you haven’t guessed yet. For example if player 1 guesses 5, the limit chosen is 20, and player 2 types 789 it would show all the numbers from 1 -20 except for the guessed 5. I thought I had completed it but when typing 789 it displays System.Collections.Generic.List`1[System.Int32] instead of the actually list. Can anyone help.
using System;
using System.Collections.Generic;
namespace NumberGuessingGameMultiplayer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to this multiplayer number guessing game! What number are you counting up to?");
int num_cap = Convert.ToInt32(Console.ReadLine()); ;
Random rnd = new Random();
int rand_num = rnd.Next(1, num_cap);
bool game_ongoing = true;
List<int> remaining = new List<int>();
for (int i = 1; i <= num_cap; i++)
{
remaining.Add(i);
}
while (game_ongoing)
{
Console.WriteLine("Player 1 guess");
int plyr1_guess = Convert.ToInt32(Console.ReadLine());
if (plyr1_guess == rand_num)
{
Console.WriteLine("Player 1 guessed the number!");
game_ongoing = false;
}
else if (plyr1_guess != rand_num && plyr1_guess != 789)
{
Console.WriteLine("Not quite Player 1");
remaining.Remove(plyr1_guess);
Console.WriteLine("Player 2 guess");
} else
{
Console.WriteLine(remaining);
int ply1_guess = Convert.ToInt32(Console.ReadLine());
if (ply1_guess == rand_num)
{
Console.WriteLine("Player 1 guessed the number!");
game_ongoing = false;
}
else if (ply1_guess != rand_num && ply1_guess != 789)
{
Console.WriteLine("Not quite Player 1");
remaining.Remove(ply1_guess);
Console.WriteLine("Player 2 guess");
}
}
int plyr2_guess = Convert.ToInt32(Console.ReadLine());
if (plyr2_guess == rand_num)
{
Console.WriteLine("Player 2 guessed the number!");
game_ongoing = false;
} else if (plyr2_guess != rand_num && plyr2_guess != 789)
{
Console.WriteLine("Incorrect Player 2");
remaining.Remove(plyr2_guess);
} else
{
Console.WriteLine(remaining);
if (plyr2_guess == rand_num)
{
Console.WriteLine("Player 2 guessed the number!");
game_ongoing = false;
}
else if (plyr2_guess != rand_num && plyr2_guess != 789)
{
Console.WriteLine("Incorrect Player 2");
remaining.Remove(plyr2_guess);
}
}
}
}
}
}
You have to iterate through the list and print each value
Or do:
remaining.ForEach(Console.WriteLine);