Hi everyone, here is my program:
In this code I am trying to create a program that selects a random question then prints it to the console, then allow the user to input the answer, and then create a text file where we can store the date, the question and the user entry, can anyone help me how to do it, because I am struggling really bad.
Thanks in advance.
C#:
using System;
using System.IO;
public class Entry
{
public static void Main()
{
Random random = new Random();
string[] journalQuestions = {
"What was the best thing that happened to you today?",
"What steps did you take today towards a goal you're working on?",
"What are three things you're grateful for today?",
"What country would you like to visit for the first time?",
"What magic power would you like to have?",
"What do you feel is your purpose in life, and has that answer changed in the last five years?",
"What is your happy place? Describe it in detail",
"Where do you see yourself in 10 years? 20?",
"What negative emotions am I holding onto? How can I let them go?",
"What goals have you lost sight of? Are you interested in picking them up again?",
"What do you want to be remembered for?" };
// Generate random indexes for journalQuestions.
int mIndex = random.Next(journalQuestions.Length);
// Display the result.
Console.Write(journalQuestions[mIndex]);
string eJournal = Console.ReadLine();
Console.WriteLine($"{eJournal}");
labelName.Text = DateTime.Now.ToString("MMM dd yyyy");
Console.Write("What is the file name: ");
string fileInput = Console.ReadLine();
string fileName = fileInput;
using (StreamWriter outputFile = new StreamWriter(filename))
{
outputFile.WriteLine("This will be the first line in the file.");
outputFile.WriteLine($" {labelName.Text} {journalQuestions[mIndex]} {eJournal}");
}
In this code I am trying to create a program that selects a random question then prints it to the console, then allow the user to input the answer, and then create a text file where we can store the date, the question and the user entry, can anyone help me how to do it, because I am struggling really bad.
Thanks in advance.
Last edited by a moderator: