dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to write a console application in Visual C# Studio 2008

  1. #1
    Join Date
    Nov 2009
    Posts
    7

    How to write a console application in Visual C# Studio 2008

    To develop a console application in the environment Visual C # Studio 2008 in accordance with the following task: There is an array of (up to 5 array) of the records with two fields: "Employee Name" (type string) and "Age" (type int) in the program.

    When you first start the program, on the screen will be showed the following menu:

    Number of employees: NO DATA
    1 - Adding an employee
    2 - Display information about all employees
    4 - Exit

    As an user you can add information about the new employee. Once again it appears the menu:

    Number of employees: 1
    1 - Adding an employee
    2 - Display information about all employees
    4 - Exit

    After pressing the 2 key (with number 2) the program will display information about all employees at the moment and again displaye the menu.

    We must use a separate function to display information about all employees

    Pressing the button 4 is out of the application.
    After pressing the button (except 1,2,4)on the screen will be showed the message "Invalid Key Pressed".

    Checking the pressed key is performed by the operator if.
    The loop in the To develop a console application in the environment Visual C # Studio 2008 in accordance with the following task: Program features an array of (up to 5 array) of the records with two fields: "Employee Name" (type string) and "Age" (type int).

    When you first start the program prints the on-screen menu:

    Number of employees: NO DATA
    1 - Adding an employee
    2 - Display information for all employees
    4 - Output

    Pressing a user can add information about the new employee. Once again it appears the menu:

    Number of employees: 1
    1 - Adding an employee
    2 - Display information for all employees
    4 - Output

    Pressing the 2 key displays information about all employees and again displayed menu.
    The output is in a separate function.
    Pressing the button 4 is out of the application.
    Pressing except 1,2,4 is the message "Invalid Key Pressed".

    Checking the pressed key is performed by the operator if.
    The loop in the main program must be do () while ()
    Defining the key pressed: function getch ()
    Following the development of applications, transfer function developed in a separate module. : do () while ()
    Defining the key pressed: function getch ()
    After developing the console application, transfer functions developed in a separate module.

    My solution is that:
    [code=csh]
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Lab1_C_sharp_
    {
    struct TWorker
    {
    public string sName;
    public int iAge;
    }
    static public void ShowInfWork(TWorker []arr, int n)
    {
    int count=0;
    for(count=0; count<n; count++)
    Console.Out.WriteLine("Worker: {0}, {1} years old", arr[count].sName,arr[count].iAge);
    }
    class Program
    {
    static void Main(string[] args)
    {
    TWorker[] arWork = new TWorker[5];
    int iNum = 0;
    char key;
    bool bDone = false;

    while ((!bDone))
    {
    Console.Clear();
    Console.Out.WriteLine("Number of workers: ");
    if (iNum == 0)
    Console.Out.WriteLine("No Data");
    else
    Console.Out.WriteLine(iNum);
    Console.Out.WriteLine(" 1 - Add worker");
    Console.Out.WriteLine(" 2 - Show information about all workers");
    Console.Out.WriteLine(" 4 - Exit");
    key = Console.ReadKey(true).KeyChar;
    switch (key)
    {
    case '4': bDone = true; break;
    case '1':
    if (iNum < 4)
    {
    Console.Out.WriteLine("Enter worker name: ");
    arWork[iNum].sName = Console.In.ReadLine();
    arWork[iNum].iAge = int.Parse(Console.In.ReadLine());
    }
    else
    Console.Out.WriteLine("You can not enter more data");
    iNum++;
    break;
    case '2':
    Console.Out.WriteLine("Information about all workers: ");
    ShowInfWork(arWork, iNum);
    key = Console.ReadKey(true).KeyChar;
    break;
    }
    }
    }
    }
    }
    [/code]
    After compiling I got some messages: "Error 3 Expected class, delegate, enum, interface, or struct" и "Error 2 Identifier expected"
    Please correct my mistakes.
    Thanks in advanced.
    Last edited by mario285; April 26th, 2010 at 02:33 AM.

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: How to write a console application in Visual C# Studio 2008

    consider this link:

    http://www.google.com/search?hl=en&s...rlz=1R2ASUS_en

    try it yourself step by step!
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,539

    Re: How to write a console application in Visual C# Studio 2008

    Hi !

    At first please read forum rules and correct your starting code Tag and reformat it, so it is forammted and could easily be read.

    Without correct code Tags code looses format and looks like yours now.
    The second point is, we dont do homework. This is also seen in the forum rules.
    So please sit down and if your code has runtime errors then simple set breakpoints and run it that way. This is a good way to learn debugging. If you have compile tome errors so your program even doesn't start ( and I think thats your trouble ) then click to the message and you will see which line is involved in your problem.

    As much as I can see you have doen a static method called ShowInfWork(...) outside a class. Methods can only be art of a class never in a namespace in C#
    This maybe will help a lot, when I'm looking to your code on a short glance
    Last edited by JonnyPoet; April 26th, 2010 at 05:14 PM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)