|
-
January 31st, 2011, 02:34 PM
#1
Newbie cant get this to work...
Hi guys, i am trying to learn c# , i am following some tutorials and now i am trying to make a simple program but just wont work.
It seems like the problem is that Console.ReadLine doesn't work , and i got no idea why...
Can you guys help me?
The error seems to be at viewDb()
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class ProgramMain
{
public static void Main()
{
DatabaseProgram db = new DatabaseProgram();
db.menu();
}
}
class DatabaseProgram
{
int count = 0;
string test;
struct database
{
public string name;
public long number;
}
database[] db = new database[50];
public void menu()
{
char choise = 'm';
while (choise != 'Q')
{
Console.WriteLine("Menu");
Console.WriteLine("A to add a new person into the database");
Console.WriteLine("B to view the database");
Console.WriteLine("Q to quit");
choise = (char) Console.Read();
switch (choise)
{
case 'A':
addPerson(ref db[count].name, ref db[count].number,ref count);
break;
case 'B':
Console.WriteLine("Test");
Console.ReadLine();
break;
case 'Q':
choise = 'Q';
break;
default:
Console.WriteLine("It can be tricky to read the instructions sometimes :) ");
break;
}
}
}
public void viewDb()
{
for (int a = 0; a != count; a++)
{
Console.WriteLine("{0}: Name {1} Sec-num: {2}", (a + 1), db[a].name, db[a].number);
}
}
public void addPerson(ref string name, ref long number, ref int count)
{
Console.WriteLine("Enter the name: ");
name = Console.ReadLine();
Console.WriteLine("Enter the sec-num");
db[count].number = Console.Read();
count++;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|