Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking an address book in C# using Arrays
    text
    copied!<p>I'm new here but basically I need some help. I've got a university assignment and I'm having some trouble with it.</p> <p>I'm trying to make an address book in C# as a console application and I've built my array and my case statement etc but I've got to a point where I don't know how to edit/add data to it.</p> <p>The array is populated with "XXXXX" and I'm supposed to be able to change those to add first name, surname, house number&amp;road name, state and zip code with row 1 being first name, row 2 being surname etc. Will the code I have written in case 1 do this or have I done that wrong?</p> <p>Also, case 3 is supposed to print the book to the screen but it is coming up with an error message saying it does not recognize s1, s2, s3, s4, s5 when I have declared them in the array. Is this because the array is separate to the rest of the program?</p> <p>here is what I have got so far, it may very well be completely wrong but any help at all will be greatly appreciated.</p> <p>Thanks alot.</p> <pre><code>using System; public static void Main() { string s1, s2, s3, s4, s5; string select; string input; char charselect; char answer; string[,] a = new string[10, 5] { {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"}, {"XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"} }; for (int i = 0; i &lt; a.Length / 5; i++) { s1 = a[i, 0]; s2 = a[i, 1]; s3 = a[i, 2]; s4 = a[i, 3]; s5 = a[i, 4]; } Console.WriteLine("Do You Want to Open The Address Book?"); Console.WriteLine("Type Y or N"); input = Console.ReadLine(); answer = Convert.ToChar(input); while (answer == 'Y') { Console.WriteLine("1. Add Entry"); Console.WriteLine("2. Delete Entry"); Console.WriteLine("3. Print Book to Screen"); select = Console.ReadLine(); { charselect = Convert.ToChar(select); char selection = (charselect); switch (selection) { case '1': string firstname; { Console.WriteLine("Please enter the first name of your entry"); firstname = Console.ReadLine(); for (int i = 0; i &lt; a.Length / 10; i++) { if (a[i, 0] == "XXXXX") { a[i, 0] = "firstname"; } } Console.ReadLine(); break; } case '2': { Console.WriteLine(""); Console.ReadLine(); break; } case '3': { Console.WriteLine("{0}, {1}, {2}, {3}, {4}", s1, s2, s3, s4, s5); Console.ReadLine(); break; } default: { Console.WriteLine("Incorrect selection, please try again"); Console.ReadLine(); break; } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload