CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  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:
    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;
    }
    }
    }
    }
    }

    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:21 AM.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

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

    Quote Originally Posted by mario285
    Please correct my mistakes.


    Are you using Visual Studio or just the .NET SDK? Whatever you are using the error will point you to the specific line of code that is causing the problem? Have you tried looking at that?

    If you want anybody to go through your code you would have to format it better. Use the code tags provided by forum. It is simple use: [code]<your pre-formatted code goes here>[ /code].

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured