Code: Show/Hide using System;
class wanked { static void Main() { string choice; string[] names; int[] ages; do { Console.Clear(); Console.WriteLine("\tMenu\n\nA - add a name\nB - add age for a name\nC - view data\nQ - Exit\n\n"); Console.WriteLine("Enter your choice: "); choice = Console.ReadLine(); switch (choice) { case "A": case "a": { int num; string input; Console.Clear(); Console.WriteLine("How many names would you like to add?: "); input = Console.ReadLine(); num = Int32.Parse(input); for (int x = 0; x < num; x++) { Console.Clear(); Console.WriteLine("Enter name for following IDs:\n"); Console.WriteLine("ID #{0}: ", x); names[x] = Console.ReadLine(); } Console.Clear(); Console.WriteLine("Enter name for following IDS:\n"); Console.WriteLine("ID #{0}: ", num); names[num] = Console.ReadLine(); } break; case "B": case "b": break; case "C": case "c": break; case "Q": case "q": break; default: Console.Clear(); Console.WriteLine("{0} is not a valid choice! Try again, press Enter Key to continue...",choice); Console.ReadLine(); Console.Clear(); break; } } while (choice != "q" && choice != "Q"); } } |
Code: Show/Hide Error 3 Use of unassigned local variable 'names' C:\Documents and Settings\Owner\Local Settings\Application Data\Temporary Projects\as\CodeFile1.cs 37 29 as
|
Code: Show/Hide for (int x = 0; x < num; x++)
{ Console.Clear(); Console.WriteLine("Enter name for following IDs:\n"); Console.WriteLine("ID #{0}: ", x); names[x] = Console.ReadLine(); } // don't need these 4 lines: Console.Clear(); Console.WriteLine("Enter name for following IDS:\n"); Console.WriteLine("ID #{0}: ", num); names[num] = Console.ReadLine(); |