Created
November 21, 2022 17:20
-
-
Save ArthurDeveloper/0609cf1630674799694bc41d236f3df7 to your computer and use it in GitHub Desktop.
Exercício em C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Linq; | |
class Program { | |
public static String[] nomes = {}; | |
public static String[] pratosPrincipais = {}; | |
public static String[] bebidas = {}; | |
public static String[] sobremesas = {}; | |
static void Main(string[] args) { | |
Console.WriteLine( | |
"Bem vindo ao programa!\n\n"+ | |
"Opções:\n"+ | |
"1 - Adicionar pedido\n"+ | |
"2 - Apagar pedido\n"+ | |
"3 - Listar pedidos\n" | |
); | |
String pedido = Console.ReadLine(); | |
if (pedido == "1") { | |
Console.WriteLine("Digite seu nome:"); | |
String nome = Console.ReadLine(); | |
Console.WriteLine("Digite seu prato principal:"); | |
String prato = Console.ReadLine(); | |
Console.WriteLine("Digite sua bebida:"); | |
String bebida = Console.ReadLine(); | |
Console.WriteLine("Digite sua sobremesa:"); | |
String sobremesa = Console.ReadLine(); | |
Array.Resize(ref nomes, nomes.Length + 1); | |
nomes[nomes.GetUpperBound(0)] = nome; | |
Array.Resize(ref pratosPrincipais, pratosPrincipais.Length + 1); | |
pratosPrincipais[pratosPrincipais.GetUpperBound(0)] = prato; | |
Array.Resize(ref bebidas, bebidas.Length + 1); | |
bebidas[bebidas.GetUpperBound(0)] = bebida; | |
Array.Resize(ref sobremesas, sobremesas.Length + 1); | |
sobremesas[sobremesas.GetUpperBound(0)] = sobremesa; | |
Console.WriteLine("\n\n\n"); | |
Main(args); | |
} else if (pedido == "2") { | |
Console.WriteLine("Digite seu nome para apagar seu pedido:"); | |
String nome = Console.ReadLine(); | |
int nomeInd = Array.FindIndex(nomes, n => n == nome); | |
if (nomeInd != -1) { | |
String nomeNoArray = nomes[nomeInd]; | |
nomes = nomes.Where(n => n != nomeNoArray).ToArray(); | |
pratosPrincipais = pratosPrincipais.Where(n => n != nomeNoArray).ToArray(); | |
bebidas = bebidas.Where(n => n != nomeNoArray).ToArray(); | |
sobremesas = sobremesas.Where(n => n != nomeNoArray).ToArray(); | |
Console.WriteLine("Pedido removido!"); | |
Thread.Sleep(1000); | |
Main(args); | |
} else { | |
Console.WriteLine("[ERRO] Pedido inexistente!"); | |
Thread.Sleep(1000); | |
Main(args); | |
} | |
} else if (pedido == "3") { | |
Console.WriteLine("\n\n\n----LISTA DE PEDIDOS----"); | |
Console.WriteLine("\n\n"); | |
for (int i = 0; i < nomes.Length; i++) { | |
Console.WriteLine($"Pedido N. {i}\n"); | |
Console.WriteLine($"Nome: {nomes[i]}"); | |
Console.WriteLine($"Prato principal: {pratosPrincipais[i]}"); | |
Console.WriteLine($"Bebidas: {bebidas[i]}"); | |
Console.WriteLine($"Sobremesas: {sobremesas[i]}"); | |
Console.WriteLine("------------------------------------------------\n\n\n"); | |
} | |
Thread.Sleep(1000); | |
Main(args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment