0

using System; using System.Collections.Generic;

public static void Main(string[] args)
{
   //Main program
   int two = 0;
   int one = 0;
                
   string[] stop = new string[16];
   stop[0] = "Brixton";
   stop[1]= "Stockwell";
   stop[2] = "Pimlico";
   stop[3] = "Vauxhall";
   stop[4] = "Victoria";
   stop[5]= "Green Park";
   stop[6] = "Oxford Circus";
   stop[7] = "Warren Street";
   stop[8] = "Euston";
   stop[9] = "King's Cross";
   stop[10] = "Highbury & IslingtoN";
   stop[11]= "Finsbury Park";
   stop[12]= "Seven Sisters";
   stop[13] = "Tottenham Hale";
   stop[14] = "Blackhorse Road";
   stop[15] = "Walthamstow Central";
    
   Console.WriteLine("What is your first stop?");
   string st1 = Console.ReadLine();
   Console.WriteLine("What is your second stop?");
   string st2 = Console.ReadLine();
            
   if (st1 == "Brixton" && st2 == "Stockwell")
   {
        Console.WriteLine(Array.IndexOf(stop, "Brixton"));
        // (Line 46)    one = Console.ReadLine();                             
   }
}
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • So what would you expect `one = Console.ReadLine();`to do? As the error says, you cannot convert a `string` to an `int` implicitly. I'm going to guess you want to use `int.Parse` or something along those lines? – UnholySheep Nov 07 '21 at 21:27

1 Answers1

0

Because anything that comes from the Console is a string. You need to parse it

one = int.Parse(Console.ReadLine());
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23
  • 2
    `one = int.TryParse(Console.ReadLine(), out int myInt) ? myInt : 0;` `TryParse` would be better, never trust the users input :) – Trevor Nov 07 '21 at 21:38