Question data being saved to a text file, and later being viewed from a username

worldtraveller123

New member
Joined
Nov 16, 2022
Messages
2
Programming Experience
Beginner
im struggling to save the user inputted data into a text file. i know that im supposed to be using stream writer and stream reader but i cannot implement it. if anyone can help itd be great, thanks.

C#:
    Console.WriteLine("Enter the marks for module 5: ");
            module5 = Convert.ToInt32(Console.ReadLine());
            while (module5 < 0 || module5 > 100)
            {
                Console.WriteLine("Enter the marks for module 5: This should be between 0-100%: ");
                module5 = Convert.ToInt32(Console.ReadLine());
            }

            Console.WriteLine("Enter the marks for module 6: ");
            module6 = Convert.ToInt32(Console.ReadLine());
            while (module6 < 0 || module6 > 100)
            {
                Console.WriteLine("Enter the marks for module 6: This should be between 0-100%: ");
                module6 = Convert.ToInt32(Console.ReadLine());
            }

            average = (module1 + module2 + module3 + module4 + module5 + module6) / 6;
            if (average < 40)
            {
                Console.WriteLine("The average mark you got was: " + average+"%");
                Console.WriteLine("You have failed");
            }
            else
            {
                Console.WriteLine("The average mark you got was: " + average + "%");
                Console.WriteLine("You have passed");
            }
            Console.ReadKey();
 
In your code above, you are not even trying to write to a text file. We won't do your work for you.
 
 
File.ReadAllText and File.WriteAllText make life simpler

Avoid using Console.ReadKey(); when you're learning to program; it works differently than most newbies expect and causes obscure bugs in your code as a result
 
Back
Top Bottom