Making a Biodata

mail@pastecode.io avatar
unknown
csharp
5 months ago
1.1 kB
2
Indexable
Never
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        string filePath = "data.csv";

        try
        {
            using (StreamWriter writer = File.CreateText(filePath))
            {
                Console.Write("Enter the number of people: ");
                int n = int.Parse(Console.ReadLine());

                for (int i = 1; i <= n; i++)
                {
                    Console.WriteLine("Enter data for person " + i + ": ");

                    Console.Write("Enter Name: ");
                    string name = Console.ReadLine();

                    Console.Write("Enter Age: ");
                    int age = int.Parse(Console.ReadLine());

                    Console.Write("Enter Gender: ");
                    char gender = char.Parse(Console.ReadLine());

                    string data = $"{name},{age},{gender}";
                    writer.WriteLine(data);
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Failed to create the file: " + e.Message);
        }
    }
}