Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 25-Apr-10 21:28pm
v2

You're just missing a brace somewhere. Just figure out where your braces don't line up and you'll be able to start debugging this for real.

Actually no. You don't seem to understand how C# works. ShowInfWork is a method that is not inside a class or struct. That's not allowed.
 
Share this answer
 
v2
The compiler will also have told you on which line it discovers these errors. Start looking at those lines more closely...
 
Share this answer
 
Move the ShowInfWork method inside the Program class. Then you should be able to get it compiled.
 
Share this answer
 

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