Issue with array (Cannot implicitly Convert Type 'int' to 'int[]')












2














I have been searching all night for a fix for a storage system for users inputs from a loop up to the limmit of 3 loop. i belive i have found it but as the title says i get the error Cannot implicitly Convert Type 'int' to 'int', on the console.readline for the user input? any suggestions on how i can solve this ?



Thank you In advnace.



            //Array For Ticket prices, sales and user input
int TicketChoices = new int[3];

//Ticket Types
//ChildT = £1.50 = Child;
//AdultT = £2.35 = Adult;
//StudentT = £1.99 = Student;

//Film Certificate Seats Screen
//Jaws 12A 15 1
//The Exorcist 18 33 2

cw("Hello Current tickets are:");

for (int I = 0; I < 3; I++)

{
cw("ID (1) Child, £1.50");
cw("ID:(2) Adult, £2,35");
cw("ID:(3) Student £1.99");
cw("");
cw("Please Select Which ticket you would like to input By Entering it's id Number");
cw("input Must be between 1-3 for it to be vaild.");
TicketChoices = int.Parse(Console.ReadLine());

}









share|improve this question



























    2














    I have been searching all night for a fix for a storage system for users inputs from a loop up to the limmit of 3 loop. i belive i have found it but as the title says i get the error Cannot implicitly Convert Type 'int' to 'int', on the console.readline for the user input? any suggestions on how i can solve this ?



    Thank you In advnace.



                //Array For Ticket prices, sales and user input
    int TicketChoices = new int[3];

    //Ticket Types
    //ChildT = £1.50 = Child;
    //AdultT = £2.35 = Adult;
    //StudentT = £1.99 = Student;

    //Film Certificate Seats Screen
    //Jaws 12A 15 1
    //The Exorcist 18 33 2

    cw("Hello Current tickets are:");

    for (int I = 0; I < 3; I++)

    {
    cw("ID (1) Child, £1.50");
    cw("ID:(2) Adult, £2,35");
    cw("ID:(3) Student £1.99");
    cw("");
    cw("Please Select Which ticket you would like to input By Entering it's id Number");
    cw("input Must be between 1-3 for it to be vaild.");
    TicketChoices = int.Parse(Console.ReadLine());

    }









    share|improve this question

























      2












      2








      2







      I have been searching all night for a fix for a storage system for users inputs from a loop up to the limmit of 3 loop. i belive i have found it but as the title says i get the error Cannot implicitly Convert Type 'int' to 'int', on the console.readline for the user input? any suggestions on how i can solve this ?



      Thank you In advnace.



                  //Array For Ticket prices, sales and user input
      int TicketChoices = new int[3];

      //Ticket Types
      //ChildT = £1.50 = Child;
      //AdultT = £2.35 = Adult;
      //StudentT = £1.99 = Student;

      //Film Certificate Seats Screen
      //Jaws 12A 15 1
      //The Exorcist 18 33 2

      cw("Hello Current tickets are:");

      for (int I = 0; I < 3; I++)

      {
      cw("ID (1) Child, £1.50");
      cw("ID:(2) Adult, £2,35");
      cw("ID:(3) Student £1.99");
      cw("");
      cw("Please Select Which ticket you would like to input By Entering it's id Number");
      cw("input Must be between 1-3 for it to be vaild.");
      TicketChoices = int.Parse(Console.ReadLine());

      }









      share|improve this question













      I have been searching all night for a fix for a storage system for users inputs from a loop up to the limmit of 3 loop. i belive i have found it but as the title says i get the error Cannot implicitly Convert Type 'int' to 'int', on the console.readline for the user input? any suggestions on how i can solve this ?



      Thank you In advnace.



                  //Array For Ticket prices, sales and user input
      int TicketChoices = new int[3];

      //Ticket Types
      //ChildT = £1.50 = Child;
      //AdultT = £2.35 = Adult;
      //StudentT = £1.99 = Student;

      //Film Certificate Seats Screen
      //Jaws 12A 15 1
      //The Exorcist 18 33 2

      cw("Hello Current tickets are:");

      for (int I = 0; I < 3; I++)

      {
      cw("ID (1) Child, £1.50");
      cw("ID:(2) Adult, £2,35");
      cw("ID:(3) Student £1.99");
      cw("");
      cw("Please Select Which ticket you would like to input By Entering it's id Number");
      cw("input Must be between 1-3 for it to be vaild.");
      TicketChoices = int.Parse(Console.ReadLine());

      }






      c# arrays






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 23:57









      dood1

      112




      112
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Here's what I think you are trying to do:



              static void Main()
          {
          //Array For Ticket prices, sales and user input
          var ticketChoices = new int[3];

          //Ticket Types
          //ChildT = £1.50 = Child;
          //AdultT = £2.35 = Adult;
          //StudentT = £1.99 = Student;

          //Film Certificate Seats Screen
          //Jaws 12A 15 1
          //The Exorcist 18 33 2

          Console.WriteLine("Hello Current tickets are:");

          for (var i = 0; i < 3; i++)

          {
          Console.WriteLine("ID (1) Child, £1.50");
          Console.WriteLine("ID:(2) Adult, £2,35");
          Console.WriteLine("ID:(3) Student £1.99");
          Console.WriteLine("");
          Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
          Console.WriteLine("input Must be between 1-3 for it to be vaild.");
          var valid = false;
          while (!valid)
          {
          var input = Console.ReadLine();
          if (int.TryParse(input, out var ticketNumber))
          {
          if (ticketNumber >= 0 && ticketNumber <= 3)
          {
          valid = true;
          }
          }

          if (valid)
          {
          ticketChoices[i] = ticketNumber;
          }
          else
          {
          Console.WriteLine("Please enter a value between 1 and 3");
          }
          }
          }

          // Print the results
          Console.WriteLine("You entered:");
          foreach (var ticketChoice in ticketChoices)
          {
          Console.WriteLine(ticketChoice);
          }

          Console.ReadLine();
          }





          share|improve this answer





























            1














            int TicketChoices = new int[3];


            TicketChoices is not an int its an array of int



            TicketChoices = int.Parse(Console.ReadLine());


            Maybe something like this instead



            var choice = int.Parse(Console.ReadLine());


            Also if you take input form a user don't, trust them to get it right



            Use TryParse Instead




            Converts the string representation of a number to its 32-bit signed
            integer equivalent. A return value indicates whether the operation
            succeeded.







            share|improve this answer































              0














              int.Parse returns a single integer. So you are trying to set TicketChoices (an array) to a single integer. That won't work.



              You can set the first integer in your array to the output of int.Parse, if that's what you want:



              TicketChoices[0] = int.Parse(Console.ReadLine());





              share|improve this answer





















                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384341%2fissue-with-array-cannot-implicitly-convert-type-int-to-int%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                Here's what I think you are trying to do:



                    static void Main()
                {
                //Array For Ticket prices, sales and user input
                var ticketChoices = new int[3];

                //Ticket Types
                //ChildT = £1.50 = Child;
                //AdultT = £2.35 = Adult;
                //StudentT = £1.99 = Student;

                //Film Certificate Seats Screen
                //Jaws 12A 15 1
                //The Exorcist 18 33 2

                Console.WriteLine("Hello Current tickets are:");

                for (var i = 0; i < 3; i++)

                {
                Console.WriteLine("ID (1) Child, £1.50");
                Console.WriteLine("ID:(2) Adult, £2,35");
                Console.WriteLine("ID:(3) Student £1.99");
                Console.WriteLine("");
                Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
                Console.WriteLine("input Must be between 1-3 for it to be vaild.");
                var valid = false;
                while (!valid)
                {
                var input = Console.ReadLine();
                if (int.TryParse(input, out var ticketNumber))
                {
                if (ticketNumber >= 0 && ticketNumber <= 3)
                {
                valid = true;
                }
                }

                if (valid)
                {
                ticketChoices[i] = ticketNumber;
                }
                else
                {
                Console.WriteLine("Please enter a value between 1 and 3");
                }
                }
                }

                // Print the results
                Console.WriteLine("You entered:");
                foreach (var ticketChoice in ticketChoices)
                {
                Console.WriteLine(ticketChoice);
                }

                Console.ReadLine();
                }





                share|improve this answer


























                  1














                  Here's what I think you are trying to do:



                      static void Main()
                  {
                  //Array For Ticket prices, sales and user input
                  var ticketChoices = new int[3];

                  //Ticket Types
                  //ChildT = £1.50 = Child;
                  //AdultT = £2.35 = Adult;
                  //StudentT = £1.99 = Student;

                  //Film Certificate Seats Screen
                  //Jaws 12A 15 1
                  //The Exorcist 18 33 2

                  Console.WriteLine("Hello Current tickets are:");

                  for (var i = 0; i < 3; i++)

                  {
                  Console.WriteLine("ID (1) Child, £1.50");
                  Console.WriteLine("ID:(2) Adult, £2,35");
                  Console.WriteLine("ID:(3) Student £1.99");
                  Console.WriteLine("");
                  Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
                  Console.WriteLine("input Must be between 1-3 for it to be vaild.");
                  var valid = false;
                  while (!valid)
                  {
                  var input = Console.ReadLine();
                  if (int.TryParse(input, out var ticketNumber))
                  {
                  if (ticketNumber >= 0 && ticketNumber <= 3)
                  {
                  valid = true;
                  }
                  }

                  if (valid)
                  {
                  ticketChoices[i] = ticketNumber;
                  }
                  else
                  {
                  Console.WriteLine("Please enter a value between 1 and 3");
                  }
                  }
                  }

                  // Print the results
                  Console.WriteLine("You entered:");
                  foreach (var ticketChoice in ticketChoices)
                  {
                  Console.WriteLine(ticketChoice);
                  }

                  Console.ReadLine();
                  }





                  share|improve this answer
























                    1












                    1








                    1






                    Here's what I think you are trying to do:



                        static void Main()
                    {
                    //Array For Ticket prices, sales and user input
                    var ticketChoices = new int[3];

                    //Ticket Types
                    //ChildT = £1.50 = Child;
                    //AdultT = £2.35 = Adult;
                    //StudentT = £1.99 = Student;

                    //Film Certificate Seats Screen
                    //Jaws 12A 15 1
                    //The Exorcist 18 33 2

                    Console.WriteLine("Hello Current tickets are:");

                    for (var i = 0; i < 3; i++)

                    {
                    Console.WriteLine("ID (1) Child, £1.50");
                    Console.WriteLine("ID:(2) Adult, £2,35");
                    Console.WriteLine("ID:(3) Student £1.99");
                    Console.WriteLine("");
                    Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
                    Console.WriteLine("input Must be between 1-3 for it to be vaild.");
                    var valid = false;
                    while (!valid)
                    {
                    var input = Console.ReadLine();
                    if (int.TryParse(input, out var ticketNumber))
                    {
                    if (ticketNumber >= 0 && ticketNumber <= 3)
                    {
                    valid = true;
                    }
                    }

                    if (valid)
                    {
                    ticketChoices[i] = ticketNumber;
                    }
                    else
                    {
                    Console.WriteLine("Please enter a value between 1 and 3");
                    }
                    }
                    }

                    // Print the results
                    Console.WriteLine("You entered:");
                    foreach (var ticketChoice in ticketChoices)
                    {
                    Console.WriteLine(ticketChoice);
                    }

                    Console.ReadLine();
                    }





                    share|improve this answer












                    Here's what I think you are trying to do:



                        static void Main()
                    {
                    //Array For Ticket prices, sales and user input
                    var ticketChoices = new int[3];

                    //Ticket Types
                    //ChildT = £1.50 = Child;
                    //AdultT = £2.35 = Adult;
                    //StudentT = £1.99 = Student;

                    //Film Certificate Seats Screen
                    //Jaws 12A 15 1
                    //The Exorcist 18 33 2

                    Console.WriteLine("Hello Current tickets are:");

                    for (var i = 0; i < 3; i++)

                    {
                    Console.WriteLine("ID (1) Child, £1.50");
                    Console.WriteLine("ID:(2) Adult, £2,35");
                    Console.WriteLine("ID:(3) Student £1.99");
                    Console.WriteLine("");
                    Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
                    Console.WriteLine("input Must be between 1-3 for it to be vaild.");
                    var valid = false;
                    while (!valid)
                    {
                    var input = Console.ReadLine();
                    if (int.TryParse(input, out var ticketNumber))
                    {
                    if (ticketNumber >= 0 && ticketNumber <= 3)
                    {
                    valid = true;
                    }
                    }

                    if (valid)
                    {
                    ticketChoices[i] = ticketNumber;
                    }
                    else
                    {
                    Console.WriteLine("Please enter a value between 1 and 3");
                    }
                    }
                    }

                    // Print the results
                    Console.WriteLine("You entered:");
                    foreach (var ticketChoice in ticketChoices)
                    {
                    Console.WriteLine(ticketChoice);
                    }

                    Console.ReadLine();
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 20 at 0:55









                    Jon Vote

                    3708




                    3708

























                        1














                        int TicketChoices = new int[3];


                        TicketChoices is not an int its an array of int



                        TicketChoices = int.Parse(Console.ReadLine());


                        Maybe something like this instead



                        var choice = int.Parse(Console.ReadLine());


                        Also if you take input form a user don't, trust them to get it right



                        Use TryParse Instead




                        Converts the string representation of a number to its 32-bit signed
                        integer equivalent. A return value indicates whether the operation
                        succeeded.







                        share|improve this answer




























                          1














                          int TicketChoices = new int[3];


                          TicketChoices is not an int its an array of int



                          TicketChoices = int.Parse(Console.ReadLine());


                          Maybe something like this instead



                          var choice = int.Parse(Console.ReadLine());


                          Also if you take input form a user don't, trust them to get it right



                          Use TryParse Instead




                          Converts the string representation of a number to its 32-bit signed
                          integer equivalent. A return value indicates whether the operation
                          succeeded.







                          share|improve this answer


























                            1












                            1








                            1






                            int TicketChoices = new int[3];


                            TicketChoices is not an int its an array of int



                            TicketChoices = int.Parse(Console.ReadLine());


                            Maybe something like this instead



                            var choice = int.Parse(Console.ReadLine());


                            Also if you take input form a user don't, trust them to get it right



                            Use TryParse Instead




                            Converts the string representation of a number to its 32-bit signed
                            integer equivalent. A return value indicates whether the operation
                            succeeded.







                            share|improve this answer














                            int TicketChoices = new int[3];


                            TicketChoices is not an int its an array of int



                            TicketChoices = int.Parse(Console.ReadLine());


                            Maybe something like this instead



                            var choice = int.Parse(Console.ReadLine());


                            Also if you take input form a user don't, trust them to get it right



                            Use TryParse Instead




                            Converts the string representation of a number to its 32-bit signed
                            integer equivalent. A return value indicates whether the operation
                            succeeded.








                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 20 at 0:13

























                            answered Nov 19 at 23:58









                            TheGeneral

                            26.7k63163




                            26.7k63163























                                0














                                int.Parse returns a single integer. So you are trying to set TicketChoices (an array) to a single integer. That won't work.



                                You can set the first integer in your array to the output of int.Parse, if that's what you want:



                                TicketChoices[0] = int.Parse(Console.ReadLine());





                                share|improve this answer


























                                  0














                                  int.Parse returns a single integer. So you are trying to set TicketChoices (an array) to a single integer. That won't work.



                                  You can set the first integer in your array to the output of int.Parse, if that's what you want:



                                  TicketChoices[0] = int.Parse(Console.ReadLine());





                                  share|improve this answer
























                                    0












                                    0








                                    0






                                    int.Parse returns a single integer. So you are trying to set TicketChoices (an array) to a single integer. That won't work.



                                    You can set the first integer in your array to the output of int.Parse, if that's what you want:



                                    TicketChoices[0] = int.Parse(Console.ReadLine());





                                    share|improve this answer












                                    int.Parse returns a single integer. So you are trying to set TicketChoices (an array) to a single integer. That won't work.



                                    You can set the first integer in your array to the output of int.Parse, if that's what you want:



                                    TicketChoices[0] = int.Parse(Console.ReadLine());






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 20 at 0:00









                                    Gabriel Luci

                                    10.2k11324




                                    10.2k11324






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384341%2fissue-with-array-cannot-implicitly-convert-type-int-to-int%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        Origin of the phrase “under your belt”?