Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7055417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:44:47+00:00 2026-05-28T03:44:47+00:00

Hello I’ve reached a stump that I cannot pull out. My program records the

  • 0

Hello I’ve reached a stump that I cannot pull out.

My program records the number of bottles collected by four rooms. The program should prompt me to enter a room number and then how many bottles that room has collected. When ever the user types in “quit” the program will spit out the bottles collected by each room and calculate the room with the most bottles collected. I should be able to add bottles to each room as long as I haven’t typed in quit.

I cannot get my GetRoom (int room) working, that is the method that does not return a value.
How would I find the room with the most bottles collected? Math.Max?

I cannot use LINQ or arrays. Its part of the assignment rules.
Heres is my code:

namespace BottleDrive1
{
    class Program
    {//Initialize 4 rooms. 
        int room1 = 0;

        int room2 = 0;

        int room3 = 0;

        int room4 = 0;

        static void Main(string[] args)
        {
            //Start of while loop to ask what room your adding into. 
            while (true)
            {
                Console.Write("Enter the room you're in: ");
                //If user enters quit at anytime, the code will jump out of while statement and enter for loop below
                string quit = Console.ReadLine();
                if (quit == "quit")
                    //Break statement allows quit to jump out of loop
                    break;
            }
        }

        private void SetRoom(int room, int value)
        {
            switch (room)
            {
                case 1:
                    room1 = value;
                    break;
                case 2:
                    room2 = value;
                    break;
                case 3:
                    room3 = value;
                    break;
                case 4:
                    room4 = value;
                    break;
            }
        }
        public void GetRoom(int room)
        {
            int count = int.Parse(Console.ReadLine());

            switch (room)
            {
                case 1:
                    room1 += count;
                    break;
                case 2:
                    room2 += count;
                    break;
                case 3:
                    room3 += count;
                    break;
                case 4:
                    room4 += count;
                    break;
                default:
                    throw new ArgumentException();
            }

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:44:48+00:00Added an answer on May 28, 2026 at 3:44 am

    Here’s an example that uses a Class to hold the information for each room. The reason for using a class is so that if your program needs to change in the future to collect more information, you won’t have to track yet another array, you can just add properties to the class.

    The individual rooms are now held in a list instead of an array just to show a different construct.

    Here is the new Room class:

    public class Room
    {
        public int Number { get; set; }
        public int BottleCount { get; set; }
    
        public Room(int wNumber)
        {
            Number = wNumber;
        }
    }
    

    And here is the new version of the program. Note that additional checking of the values entered by the end user has been added in order to prevent exceptions when trying to get the current room or parse to an int the value entered by the user:

        static void Main(string[] args)
        {
            const int MAX_ROOMS = 4;
            var cRooms = new System.Collections.Generic.List<Room>();
    
            for (int nI = 0; nI < MAX_ROOMS; nI++)
            {
                // The room number is 1 to 4
                cRooms.Add(new Room(nI + 1));
            }
    
            // Initializes the room that wins
            //Start of while loop to ask what room your adding into. 
            while (true)
            {
                Console.Write("Enter the room you're in: ");
                //If user enters quit at anytime, the code will jump out of while statement and enter for loop below
                string roomNumber = Console.ReadLine();
                if (roomNumber == "quit")
                {
                    //Break statement allows quit to jump out of loop
                    break;
                }
                int room = 0;
                if (int.TryParse(roomNumber, out room) && (room < MAX_ROOMS) && (room >= 0)) {
                    Room currentRoom;
    
                    currentRoom = cRooms[room];
    
                    Console.Write("Bottles collected in room {0}: ", currentRoom.Number);
    
                    int wBottleCount = 0;
    
                    if (int.TryParse(Console.ReadLine(), out wBottleCount) && (wBottleCount >= 0))
                    {
                        // This line adds the count of bottles and records it so you can continuously count the bottles collected.
                        currentRoom.BottleCount += wBottleCount;
                    }
                    else
                    {
                        Console.WriteLine("Invalid bottle count; value must be greater than 0");
                    }
                }
                else
                {
                    Console.WriteLine("Invalid room number; value must be between 1 and " + MAX_ROOMS.ToString());
                }
            }
    
            Room maxRoom = null;
    
            foreach (Room currentRoom in cRooms) //This loop goes through the array of rooms (4)
            {
                // This assumes that the bottle count can never be decreased in a room
                if ((maxRoom == null) || (maxRoom.BottleCount < currentRoom.BottleCount))
                {
                    maxRoom = currentRoom;
                }
                Console.WriteLine("Bottles collected in room {0} = {1}", currentRoom.Number, currentRoom.BottleCount);
            }
            //Outputs winner
            Console.WriteLine("And the Winner is room " + maxRoom.Number + "!!!");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello, Im working on a solution for Android that will record calls (both out
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello I am compiling a program with make but I get the error of
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello everyone i am trying to format the input number range with php number_format
Hello guys I need to pass a string array over to a setter that
Hello Guys I am trying to figure out why i am gettings this error
Hello I have a number of crystal reports in my VS2008 project. I am
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello i would like do somthing like that: <?php $count = 0; foreach($a as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.