I cant save my input in my array, so when i put all the answers in, and i want to se what i have in my array, all the spots are empty. This is whats happening since i put the if-statement there. If i remove the if-statement, the input will be saved in my array but it will miss the first input, so i will have 23 out of 24 answers.
Ive tried to write an else-statement aswell, but same problem with the one missing, same if i delete the whole if-statement.
{
if (numberOfBottles < 24)
{
Console.WriteLine("");
Console.WriteLine("Write what sodas u want in the crate:"); // Skriver ut text och ber användaren skriva drycken.
int soda_input = 0;
string chosenSoda = "";
do
{
Console.WriteLine("1: Coca-cola"); // skriver ut alternativen för flaska
Console.WriteLine("2: Fanta");
Console.WriteLine("3: Pepsi");
Console.WriteLine("4: Beer");
Console.WriteLine("5: Redbull");
Console.WriteLine("6: Cider");
Console.WriteLine("7: Water");
try
{
soda_input = int.Parse(Console.ReadLine());
}
catch (Exception e)
{
Console.WriteLine("Just numbers, my friend");
continue;
}
if (chosenSoda == null)**
{
crate[numberOfBottles] = chosenSoda; // lagrar svaren i min vektor
} THIS IS THE IF-STATEMENT THAT IS MESSING EVERYTHING UP
numberOfBottles++; // för varje svar jag skriver så ökar det med 1 i vektorn hela vägen till 24
switch (soda_input) // Skapar en meny, som skriver ut vilken dryck användaren väljer tills backen blir full.
{
case 1:
chosenSoda = "Coca-Cola";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Coca-Cola");
Console.WriteLine("-------------------");
break;
case 2:
chosenSoda = "Fanta";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Fanta");
Console.WriteLine("-------------------");
break;
case 3:
chosenSoda = "Pepsi";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Pepsi");
Console.WriteLine("-------------------");
break;
case 4:
chosenSoda = "Öl";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Öl");
Console.WriteLine("-------------------");
break;
case 5:
chosenSoda = "Redbull";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Redbull");
Console.WriteLine("-------------------");
break;
case 6:
chosenSoda = "Cider";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Cider");
Console.WriteLine("-------------------");
break;
case 7:
chosenSoda = "Vatten";
Console.WriteLine("-------------------");
Console.WriteLine("Du valde Vatten");
Console.WriteLine("-------------------");
break;
default: // om man skriver siffror ovanför 1-7 så skrivs detta ut.
Console.WriteLine("-------------------");
Console.WriteLine("Siffor mellan 1-7 min vän");
Console.WriteLine("-------------------");
break;
}
} while (numberOfBottles != 24);
}
else
Console.WriteLine("");
Console.WriteLine("The crate is full, choose some of the alteratives to check the crate:");
Console.WriteLine("");
}
EDIT: "Du valde, means U chose.. in swedish.
Aucun commentaire:
Enregistrer un commentaire