Opgepast! Het lijkt erop dat je Dodona gebruikt binnen een andere webpagina waardoor mogelijk niet alles goed werkt. Laat dit weten aan de lesgever zodat die het probleem kan oplossen door een instelling in de leeromgeving aan te passen. Ondertussen kan je op deze link klikken om Dodona te openen in een nieuw venster.
Opgepast! De pagina kon niet volledig ingeladen worden, waarschijnlijk door een netwerkprobleem. Het kan zijn dat niet alle functionaliteit beschikbaar is. Probeer de pagina te verversen.
- Level 6 - Count controlled iterations and scope
- Countdown to launch
- Rainfall
- Notebook
- Times tables
- Voting count
- Fizz Buzz
- Find and replace
- Twelve days of Christmas
- Distribution of two dice
Log in om je oplossingen te testen.
// 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);
}
}
}