How to print the array with added data

Asked

Viewed 24 times

-3

I’m creating a parking console app to train how to use c#, but I’m having an error when displaying an array of customer data lists that I add to it, I tried to change the interpolation I did but the error persists in different ways. Change the interpolation to the

a. Person named

it does not print the second list with customer data.

here is the main code.

using System;

namespace AppEstacioanamento
{
    class Program
    {
        static void Main(string[] args)
        {
            Carros[] carros = new Carros[5];
            var indiceCarro = 0;

            string opcaoCarros = obterLista();

            //instanciar a classe carro.
            Carros carro = new Carros();
            //instancia a classe vaga.
            Vaga vaga = new Vaga();

            while (opcaoCarros.ToUpper() != "X")
            {
                switch (opcaoCarros)
                {
                    case "1":
                        // Adc Carro a lista.
                        Console.WriteLine("Informe o modelo.");
                        carro.Marca = Console.ReadLine();

                        Console.WriteLine("Informe o marca:");
                        carro.Modelo = Console.ReadLine();

                        Console.WriteLine("Informe a Placa:");
                        carro.Placa = Console.ReadLine();

                        carros[indiceCarro] = carro;
                        indiceCarro++;
                        

                        Console.WriteLine("Nome:");
                        carro.NomePessoa = Console.ReadLine();

                        Console.WriteLine("CPF:");
                        bool cpf = Vaga.validar(Console.ReadLine());
                        while (cpf == false)
                        {
                            cpf = Vaga.validar(Console.ReadLine());
                            if (cpf == false)
                            {
                                Console.WriteLine("CPF inválido!");
                            }
                        }
                        break;

                    case "2":
                        foreach (var a in carros)
                        {

                            if (!string.IsNullOrEmpty(a.NomePessoa))
                            {
                                Console.WriteLine($"NOME:{a.NomePessoa}");
                                Console.WriteLine($"CARRO:{a.Marca}");
                                Console.WriteLine($"MARCA: {a.Modelo}");
                                Console.WriteLine($"PLACA: {a.Placa}");
                                Console.WriteLine();
                            }
                        }
                        break;

                    case "3":
                        Console.WriteLine("Numero da Vaga:");
                        vaga.NumVaga = Console.ReadLine();

                        Console.WriteLine("Hora de entrada:");
                        Console.ReadLine();
                        break;

                    case "4":
                        //informar valor de cada cliente.
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();

                }
                opcaoCarros = obterLista();
            }
        }
        private static string obterLista()
        {
            Console.WriteLine();
            Console.WriteLine("***SITEMA PARA ESTACIONAMENTO***");
            Console.WriteLine("----------------------------------");
            Console.WriteLine();
            Console.WriteLine(" Informe qual opção desejada");
            Console.WriteLine("==================================");
            Console.WriteLine(" 1 - Inserir novo veiculo:");
            Console.WriteLine("==================================");
            Console.WriteLine(" 2 - Listar veiculos:");
            Console.WriteLine("==================================");
            Console.WriteLine(" 3 - Numero da vaga");
            Console.WriteLine("==================================");
            Console.WriteLine(" 4 - Informar valor ao cliente:");
            Console.WriteLine("==================================");
            Console.WriteLine(" X - Sair");
            Console.WriteLine();

            string opcaoCarros = Console.ReadLine();
            return opcaoCarros;
        }
    }
}

  • I will not be registering cars to solve your problem, create a [mcve] that plays and that takes the reader of the question straight to the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.