Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click
this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
Level 6 - Count controlled iterations and scope
0/9 0 of 9 activities solved
Countdown to launch
Not yet solved
Rainfall
Not yet solved
Notebook
Not yet solved
Times tables
Not yet solved
Voting count
Not yet solved
Fizz Buzz
Not yet solved
Find and replace
Not yet solved
Twelve days of Christmas
Not yet solved
Distribution of two dice
Not yet solved
Next series
Assessment point - Levels 1-6
Previous activity
Rainfall
Next activity
Times tables
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);
}
}
}
Feedback