5 Replies - 131 Views - Last Post: 02 February 2012 - 01:55 PM Rate Topic: -----

Topic Sponsor:

#1 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

return menu

Posted 02 February 2012 - 01:03 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class WasteSchedul
    {
        public void start()
        {

            int choice = -1;

            while (choice != 0)
            {
                WriteMenuText();
                choice = int.Parse(Console.ReadLine());
                {
                    if (choice == 1)
                        Bin1();
                    else
                        Bin2();

                }
            }
        }
                
                public void WriteMenuText()

        {
            Console.WriteLine("\n1 Bin 1");
            Console.WriteLine("2 Bin 2 ");
            Console.WriteLine("0 Exit the program");
            Console.Write("\nYour choice ");
                }
        
        private void Bin1()
        {
            int count = 52;
            int p = 0;
            const int cols = 3;
            string montera = "";
            for (int i = 1; i <= count; i += 2)
            {
                montera += string.Format("{0,10} {1,2}", "Week", i);
                p++;
                if ((p >= cols) && (p % cols == 0))
                {
                    Console.WriteLine(montera);
                    montera = "";

                }
            }
            Console.WriteLine(montera);
            Console.WriteLine("\nBin number 1 is emptied the following weeks ");
            Console.WriteLine("-------------------------------------------------------");
            Console.ReadLine();
        }
        private void Bin2()
        {
            int count = 52;
            int p = 0;
            const int cols = 3;
            string montera = "";
            for (int i = 5; i <= count; i += 6)
            {
                montera += string.Format("{0,10} {1,2}", "Week", i);
                p++;
                if ((p >= cols) && (p % cols == 0))
                {
                    Console.WriteLine(montera);
                    montera = "";

                }
            }
            Console.WriteLine(montera);
            Console.WriteLine("\nBin number 2 is emptied the following weeks ");
            Console.WriteLine("-------------------------------------------------------");
            Console.ReadLine();
        }
    }
}


I get every thing to work but the program dont exit when i type 0 it comes to 2 i think i need to do a else if or can i do samthing else? and can anyone tell me how i return the menu after i type in 1

Is This A Good Question/Topic? 0
  • +

Replies To: return menu

#2 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3290
  • View blog
  • Posts: 6,896
  • Joined: 02-June 10

Re: return menu

Posted 02 February 2012 - 01:13 PM

Reminder to new folks: This is homework and we don't provide completed code for homework. Rather we try to help the student comprehend the concept they are struggling with so they can write their own code. They are being graded on their skill not ours.

This is the 'Help me with my homework' article you wanted.


I really can't understand your one big run-on sentence very well - so please forgive me if I am misinterpreting what you are asking.

"How I return the menu" - You want to return a menu object/class from one of your methods?

Quote

dont exit when i type 0 it comes to 2

Yeah, you told it to do that.

If user inputs '1' do Bin1().
if the user inputs ANYTHING ELSE do Bin2
if (choice == 1)
                        Bin1();
                    else
                        Bin2();

Personally I'd use a switch construct for the possibilities, but maybe your class hasn't done that yet.

Just add another if condition for if (choose == 2)
Was This Post Helpful? 0
  • +
  • -

#3 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

Re: return menu

Posted 02 February 2012 - 01:34 PM

thx i know about the switch but i dont know how im going to get them in to it when is on the same class and it is a private to.

I try to get Bin1 Bin2 when i get them over int choice = -1;
but i only get a error then
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3290
  • View blog
  • Posts: 6,896
  • Joined: 02-June 10

Re: return menu

Posted 02 February 2012 - 01:46 PM

I don't understand. Do you have new code you can show us? What is the error? "An error" doesn't help us to help you.

None of this has anything to do with the class it's in or whether or not its private.

I don't think you really understand the few code statements you are using at the moment... or what a switch statment is.


choice = int.Parse(Console.ReadLine());
switch (choice)
{
      case 0:
         // Do this if user enters '0'
         break;
      case 1:
        // do this if user enters '1'
        break;
      case 2: 
         // do this if user enters '2'
         break;
}


I strongly urge you to go back through your textbook and learn these statements better and even seek the teacher's help in understanding them before you trying to build upon this foundation.

This post has been edited by tlhIn`toq: 02 February 2012 - 01:46 PM

Was This Post Helpful? 0
  • +
  • -

#5 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

Re: return menu

Posted 02 February 2012 - 01:50 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class WasteSchedul
    {
        public void start()
        {
            Bin1();
                Bin2();

            int choice = -1;

            while (choice != 0)
            {
                //visar menu 
                WriteMenuText();
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                    case 1:
                        {
                            Bin1
                                break;
                        }
                    case 2:
                        {

                                break;
                        }

this on the top end you know the rest:P
maybe the Bin1 Bin2 is not going to be ther

i get a error like this.
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • WillMyCodeWork = !FailedWhenYouTriedIt;
  • member icon

Reputation: 3290
  • View blog
  • Posts: 6,896
  • Joined: 02-June 10

Re: return menu

Posted 02 February 2012 - 01:55 PM

26 Bin1

Not Bin1

Bin1();

You need to wake up, go for a walk or something. This is just proofreading your own typing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1