I am developing a program that collects the results of a “bottle drive”. The program will prompt the user for a room number, between 1 and 4, and then prompt the user for the number of bottles collected by each room. The user should have the option to type “quit” to display each room and the number of bottles collected.
Here is my code right now, I am having difficulty expanding the program to support multiple rooms.
namespace BottleDrive
{
class Program
{
static void Main(string[] args)
{
int roomNumber;
int numberOfBottles;
char quit;
Console.WriteLine("Enter the Room number you are in.");
string roomSelect = "";
roomSelect = Console.ReadLine();
roomSelect = int.Parse(roomSelect);
if (roomSelect >= 1)
{
Console.WriteLine("Enter the number of bottles collected by room one");
string room1Bottles = "0";
room1Bottles = Console.ReadLine();
int room1 = int.Parse(room1Bottles);
if (room1 == 1)
{
room1Bottles += room1;
Console.WriteLine("Room one has " + room1 + " many bottles collected");
}
}
if (Console.ReadLine() = quit)
{
Console.WriteLine("Room one has collected:" + room1Bottles + "\nRoom two has collected:" + room2Bottles + "Press space to quit");
string systemExit = "";
if (Console.ReadLine = "")
{
systemExit(0);
}
}
You could utilize an array (the room number would be used to calculate the index) to keep track of the number of bottles collected:
Then you could iterate through the array again once the user types “quit” to show how many bottles were collected.