Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need to create a console application that stores a users name and phone number in a multidimensional array, at the moment I do not know how to get the program to read the information that the users has entered and store it in an array.

What I have so far

C#
using System;
public class Phonebook
{
    public static void Main()
    {
        String inputname, inputPhoneNo, userselection;

        String[,] name = new string[20,20];


        Console.WriteLine("Please select and option" +
        Environment.NewLine + "1. Add Entry" +
        Environment.NewLine + "2. Delete Entry" +
        Environment.NewLine + "3. Print Book to Screen" +
        Environment.NewLine + "4. Continue 'Y' or 'N'");
        userselection = Console.ReadLine();

        switch (userselection)
        {
            case "1":
           string [] = Console.ReadLine();
                break;
Posted

(If I got you) You need something like this:

C#
public static void Main()
    {
      String inputname, inputphoneno, userselection;

      String[,] addrbook = new string[20, 2];

      int n = 0;
      do
      {
        Console.WriteLine("Please select and option" +
        Environment.NewLine + "1. Add Entry" +
        Environment.NewLine + "2. Delete Entry" +
        Environment.NewLine + "3. Print Book to Screen" +
        Environment.NewLine + "4. Quit");
        userselection = Console.ReadLine();

        switch (userselection)
        {
          case "1":
            Console.WriteLine("Name:");
            addrbook[n,0] = Console.ReadLine();
            Console.WriteLine("Phone No.:");
            addrbook[n,1] = Console.ReadLine();
            break;
          case "2":
            // code for entry removal
            break;
          case "3":
            // code for printing the address book
            break;
          case "4":
            break;
        }
        n++;
      } while (userselection != "4");
    }
 
Share this answer
 
Could you please explain a bit about that part which prints the code and removing the code?
I am struggling on them.
 
Share this answer
 
Comments
PaulN18 8-Nov-12 18:23pm    
You're studying computer science at Anglia Ruskin, aren't you?
Amir No-Family 20-Jun-18 7:41am    
lol how did you know? Just looking back at my code, I was really noob haha
no worries, I sorted the matter out.
 
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