C
ConsoleReadLine
Guest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AmiralBattı
{
class Program
{
static void Main(string[] args)
{
bool gameContinues = true;
while (gameContinues == true)
{
try
{
Console.Write("Enter a number in 0 to 8 range: ");
int choice = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Game(choice));
}
catch
{
Console.WriteLine("Wrong type input.");
}
}
Console.ReadLine();
}
static int Game(int choice)
{
int ships;
switch (choice)
{
case 0:
ships = 12345678;
break;
case 1:
ships = 02345678;
break;
case 2:
ships = 01345678;
break;
case 3:
ships = 01245678;
break;
case 4:
ships = 01235678;
break;
case 5:
ships = 01234678;
break;
case 6:
ships = 01234578;
break;
case 7:
ships = 01234568;
break;
case 8:
ships = 01234567;
break;
default:
Console.WriteLine("Invalid number");
break;
}
return ships;
}
}
Use of unassigned local variable 'ships' error kicks when I run the program.
View: https://www.youtube.com/watch?v=GhQdlIFylQ8
in the video, at 2:24:30, Mike is able to initiate his program with same code line I have.
I am confused and I seek help from the Microsoft Comunity.
Continue reading...
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AmiralBattı
{
class Program
{
static void Main(string[] args)
{
bool gameContinues = true;
while (gameContinues == true)
{
try
{
Console.Write("Enter a number in 0 to 8 range: ");
int choice = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Game(choice));
}
catch
{
Console.WriteLine("Wrong type input.");
}
}
Console.ReadLine();
}
static int Game(int choice)
{
int ships;
switch (choice)
{
case 0:
ships = 12345678;
break;
case 1:
ships = 02345678;
break;
case 2:
ships = 01345678;
break;
case 3:
ships = 01245678;
break;
case 4:
ships = 01235678;
break;
case 5:
ships = 01234678;
break;
case 6:
ships = 01234578;
break;
case 7:
ships = 01234568;
break;
case 8:
ships = 01234567;
break;
default:
Console.WriteLine("Invalid number");
break;
}
return ships;
}
}
Use of unassigned local variable 'ships' error kicks when I run the program.
in the video, at 2:24:30, Mike is able to initiate his program with same code line I have.
I am confused and I seek help from the Microsoft Comunity.
Continue reading...