Level 6 - Count controlled iterations and scope 0 of 9 activities solved
  1. Countdown to launch Not yet solved
  2. Rainfall Not yet solved
  3. Notebook Not yet solved
  4. Times tables Not yet solved
  5. Voting count Not yet solved
  6. Fizz Buzz Not yet solved
  7. Find and replace Not yet solved
  8. Twelve days of Christmas Not yet solved
  9. Distribution of two dice Not yet solved
Next series Assessment point - Levels 1-6
Level 6 - Count controlled iterations and scope

Notebook

Sign in to hand in your solution and get feedback.

// 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); } } }