School club

Log in om je oplossingen te testen.
// School club program using System; using System.IO; using System.Collections.Generic; class Submission { // ------------------------- // Subprograms // ------------------------- static void add_student() { StreamWriter file = new StreamWriter("programming.txt", true); Console.WriteLine("Enter your name to sign up for the club:"); string student = Console.ReadLine(); file.WriteLine(student); file.Close(); Console.WriteLine($"You have been signed up, {student}"); } static void show_students() { Console.WriteLine($"Students that signed up for the programming club:"); List<string> students = new List<string>(); StreamReader file = new StreamReader("programming.txt"); string line; while ((line = file.ReadLine()) != null) { students.Add(line.Trim()); } file.Close(); foreach (string student in students) { Console.WriteLine(student); } } static void menu() { Console.WriteLine("1. Sign up"); Console.WriteLine("2. Show students"); string choice = ""; while (choice != "1" && choice != "2") { Console.WriteLine("Enter choice:"); choice = Console.ReadLine(); } switch (choice) { case "1": add_student(); break; case "2": show_students(); break; } } // ------------------------- // Main program // ------------------------- public static void Main(string[] args) { menu(); } }
Je kunt zo vaak indienen als je wenst. Er wordt enkel rekening gehouden met je laatst ingediende oplossing.
Log in om je oplossingen te testen.