Level 6 - Count controlled iterations and scope 0 van 9 activiteiten opgelost
  1. Countdown to launch Nog niet opgelost
  2. Rainfall Nog niet opgelost
  3. Notebook Nog niet opgelost
  4. Times tables Nog niet opgelost
  5. Voting count Nog niet opgelost
  6. Fizz Buzz Nog niet opgelost
  7. Find and replace Nog niet opgelost
  8. Twelve days of Christmas Nog niet opgelost
  9. Distribution of two dice Nog niet opgelost
Volgende reeks Assessment point - Levels 1-6
Level 6 - Count controlled iterations and scope

Notebook

Meld je aan om je oplossing in te dienen en feedback te krijgen.

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