Level 8 - Files and exceptions 0 van 9 activiteiten opgelost
  1. Saving data Nog niet opgelost
  2. School club Nog niet opgelost
  3. Shopping list Nog niet opgelost
  4. Attributes Nog niet opgelost
  5. Cookies Nog niet opgelost
  6. Morse code Nog niet opgelost
  7. ini file Nog niet opgelost
  8. Amino acids Nog niet opgelost
  9. Gamertag Nog niet opgelost
Volgende reeks Level 9 - Two-dimension arrays and lists
Level 8 - Files and exceptions

School club

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

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