Click here to Skip to main content
15,868,049 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys,
I'm currently working on a project to create an auction house system in a C# console application. I was wondering how I would be able to implement a menu in the console once I have logged in where you could press a number and it would show up that section.
For example:
1 - Browse Auction
2 - List Auction
3 - Listed Items
4 - Exit

Is it possible that I would need to add a seperate class like "keypad" or can I implement it in this code?

Here is the code I have so far:


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;

            Console.WriteLine("Please enter a username");
            input = Console.ReadLine();
            if (input == "John")
            if (input != "John")
               error();

            Console.WriteLine("Please enter a password");
            input = Console.ReadLine();
            if (input == "Smith")
                menu();
            if (input != "Smith")
               error();

        }

               static void menu()
               {
                   Console.WriteLine("Welcome!");
                   Console.ReadLine();
            }

        static void error()
        {
            Console.WriteLine("error");

        }
    }
}
Posted
Updated 16-Mar-13 16:01pm
v2
Comments
Jegan Thiyagesan 16-Mar-13 21:51pm    
Description of your question and your code doesn't match. Where is the code that actually do something, apart from a console application that reads a name?
TableSalt 16-Mar-13 21:59pm    
This is the only code I have done so far. What I want to know is when creating a menu with the numbers does that need to be in a separate class? And also how would I be able to have that menu show up immediately after logging in without there being any errors?
Jegan Thiyagesan 17-Mar-13 6:03am    
The description of your project sound moderate amount of coding involved, but you saying, the code above is a first code you have written. It sounds you need a lot of homework to do on programming before even you think about doing this project.
PIEBALDconsult 16-Mar-13 22:38pm    
You can, but why not WinForms?

1 solution

Couldn't you just use a switch statement? Like so:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            Console.WriteLine("Please enter a username");
            input = Console.ReadLine();
            if (input != "John")
            {
               error();
            }

            Console.WriteLine("Please enter a password");
            input = Console.ReadLine();
            if (input == "Smith")
                menu();
            if (input != "Smith")
               error();
 
        }
 
               static void menu()
               {
                   Console.WriteLine("Welcome!");
                   Console.WriteLine("Please enter a command");
                   string input = (int)Console.ReadLine();
                   switch(input)
                   {
                      case 1:
                       //Run browse auction stuff...
                      case 2:
                       //Run list auction stuff...
                      case 3:
                       //Run listed items stuff...
                      case 4:
                       //Exit...
                   }
            }


I just wrote this now, so didn't test it... It should work though.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900