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 7074883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:41+00:00 2026-05-28T06:06:41+00:00

My program is supposed to tally up bottles from 4 rooms. When the user

  • 0

My program is supposed to tally up bottles from 4 rooms. When the user types in quit, the program spits out how many bottles each room has collected.

I have a problem when the program prompts the user, it prompts twice but takes the last entered number as the selected roomNumber. I also do not know how to set up my if statements so I can continuously add up the bottles entered by the user to each specific room.

Can I use a temporary variable to store the entered bottle count then add it to the room1, room2 which holds the current bottle count number?

namespace BottleDrive1 {
    class Program {
        static void Main(string[] args)
        {
            //Initialize 4 rooms. 
            int room1 = 0;
            int room2 = 0;
            int room3 = 0;
            int room4 = 0;
            int roomNumber;
            while (true)
            {
                Console.WriteLine("Enter the the room number you are in.");
                string quit = Console.ReadLine();
                if (quit == "quit")
                {
                    //Break statement allows quit to jump out of loop
                    break;
                }
                //int roomT = int.Parse(quit);//a temp variable I want to use to add bottles to the count.
                roomNumber = int.Parse(Console.ReadLine());

                if (roomNumber == 1)
                {
                    Console.WriteLine("How many bottles did room 1 collect?");
                    room1 = int.Parse(Console.ReadLine());
                }
                if (roomNumber == 2)
                {
                    Console.WriteLine("How many bottles did room 2 collect?");
                    room2 = int.Parse(Console.ReadLine());
                }
                if (roomNumber == 3)
                {
                    Console.WriteLine("How many bottles did room 3 collect?");
                    room3 = int.Parse(Console.ReadLine());
                }
                if (roomNumber == 4)
                {
                    Console.WriteLine("How many bottles did room 4 collect?");
                    room4 = int.Parse(Console.ReadLine());
                }

            }
            Console.WriteLine("Bottles each room has collected:");
            Console.WriteLine("Room one:" + room1);
            Console.WriteLine("Room two:" + room2);
            Console.WriteLine("Room three:" + room3);
            Console.WriteLine("Room four:" + room4);
            int maxRoom = room1;
            if (room2 > maxRoom)
            {
                maxRoom = 2;
            }
            if (room3 > maxRoom)
            {
                maxRoom = 3;
            }
            if (room4 > maxRoom)
            {
                maxRoom = 4;
            }
            else
            {
                maxRoom = 1;
            }
            Console.WriteLine("The winner is room " + maxRoom + "!");
        }
    }
}
  • 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-28T06:06:42+00:00Added an answer on May 28, 2026 at 6:06 am

    You were very close! In your while loop, you read the value for quit from console and you “prompt” the user to enter the room number again by reading from console one more time. You can avoid the second “prompt” by simply taking the value of quit and parsing the room number. Note that everything will work fine, because if the user enters quit, then you will exit the loop anyway:

    while (true) 
    {
        Console.WriteLine("Enter the the room number you are in.");
        string quit = Console.ReadLine();
    
        // another quick thing to fix is to ignore the case (don't trust the user)
        if(quit .Equals("quit", StringComparison.InvariantCultureIgnoreCase))
        {
            //Break statement allows quit to jump out of loop
            break;
        }
    
        roomNumber = int.Parse(quit); // you've already asked the user for input, so just reuse the variable holding the input
    
        // TODO: consider what happens if you can't parse an integer, i.e. use TryParse etc
    
        // do whatever you need to do after that
    }
    

    After you get the room number, then don’t forget to add the number of bottles with the ‘+= operator’, e.g.:

    room4 += int.Parse(Console.ReadLine());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program is supposed to read an integer n from the user and then
I am supposed to write a program that gets some PNG images from the
PLease help me out here. The program is supposed to recursively find out the
I have an assignment from school where the program is supposed to close when
The program is supposed to take user input, turn it into html and pass
So, this program is supposed to take stats from Auburn's football season and compute
My class assignment is to write a program that has the user input a
Working on a school project, the program is supposed to read from a text
Update this program is supposed to keep track of the number of times each
The program is supposed to accept telnet connections on port 8888 and then send

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.