Notebook

Sign in to test your solution.
// Notebook program using System; class Submission { // ------------------------- // Subprograms // ------------------------- // Return valid note index (0-9) static int get_note_number() { int note_number = 0; bool valid_input = false; while (!valid_input) { note_number = Convert.ToInt32(Console.ReadLine()); if (note_number >= 0 && note_number < 10) { valid_input = true; } else { Console.WriteLine("Invalid input. Enter 0-9."); } } return note_number; } // Write a new note static void add_note(string[] notebook) { int index = get_note_number(); string note = Console.ReadLine(); notebook[index] = note; } // Clear the whole notebook (after confirmation) static void clear_notes(string[] notebook) { string choice = ""; while (choice != "y" && choice != "n") { choice = Console.ReadLine(); } if (choice == "y") { for (int index = 0; index < notebook.Length; index++) { notebook[index] = ""; } } } // Sort notes alphabetically static void order_notes(string[] notebook) { Array.Sort(notebook); } // Show the notebook static void show_notebook(string[] notebook) { for (int index = 0; index < notebook.Length; index++) { Console.WriteLine($"{index} : {notebook[index]}"); } } // Menu (returns false when the user quits) static bool menu(string[] notebook) { Console.WriteLine(); Console.WriteLine("a. Add note"); Console.WriteLine("c. Clear notebook"); Console.WriteLine("o. Order notes"); Console.WriteLine("q. Quit"); string choice = Console.ReadLine(); if (choice == "q") { return false; } switch (choice) { case "a": add_note(notebook); break; case "c": clear_notes(notebook); break; case "o": order_notes(notebook); break; } return true; } // ------------------------- // Main program // ------------------------- public static void Main(string[] args) { string[] notebook = new string[10]; for (int i = 0; i < notebook.Length; i++) { notebook[i] = ""; } bool running = true; while (running) { show_notebook(notebook); running = menu(notebook); } } }
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.