// School club program
using System;
using System.IO;
using System.Collections.Generic;
public class Program
{
// -------------------------
// Subprograms
// -------------------------
static void add_student()
{
StreamWriter file = new StreamWriter("programming.txt", true);
Console.Write("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
// -------------------------
static void Main()
{
menu();
}
}