I'm trying to build a program that lets the user choose between 3 options.
- Seeing how many coins they have.
- Adding coins to their collection.
- Taking coins from their collection.
I made a while loop with the menu first. After that I made a switch statement with different cases depending on what the user chose. If the user chooses option nr 2 and adds for example 3 coins. It is saved in collection for the next loop. But if the user wants to add more coins again. Then the value of the collection resets. I want the user to be able to add more coins to their collection everytime the while loop runs. So the user first can add 2 coins, then choose to see the menu again, then choose to add 2 more coins, then choose to see the menu again, then if the user wants to see the collection, it should be 4 coins. Thanks
float add, take, collection;
collection = 0;
bool on = true;
while (on)
{
Console.WriteLine("See collection press 1");
Console.WriteLine("Add to collection press 2");
Console.WriteLine("Take from collection press 3");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
Console.WriteLine("You have " + collection + " coins");
Console.Write("Want to see the menu again? Press K ");
string str = Console.ReadLine();
if (str != "K")
{
on = false;
}
break;
case "2":
Console.Write("How many coins do you want to add?: ");
string str1 = Console.ReadLine();
add = float.Parse(str1);
collection =+ add;
Console.WriteLine("You now have " + collection + " in your collection");
Console.Write("Want to see the menu again? Press K");
string str2 = Console.ReadLine();
if (str2 != "K")
{
on = false;
}
break;
case "3":
Console.Write("How many coins do you want to take?: ");
string str3 = Console.ReadLine();
take = float.Parse(str3);
collection =- take;
Console.WriteLine("You now have " + collection + " in your collection");
Console.Write("Want to see the menu again? Press K");
string str4 = Console.ReadLine();
if (str4 != "K")
{
on = false;
}
break;
}
}