Programming
Code problem

Question Description

I’m studying and need help with a Programming question to help me learn.

Hi. I have at school a program in C# console application to create 2 menus. I created the first one, i can choose any option i want, the point is the first option is to log in. if success i need to go into 2nd menu. but when i go into 2nd menu i can't choose any option. here is my code:

The one that is commented is the one that doesnt work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Unit18_CW_ID12389
{
  class Program
  {
  static void Main(string[] args)
  {
   
  int option = 0;
  //int option1 = 0;
  option = DisplayMenu();
   
  if (option == 1)
  {
  //call SignIn() method
  SignIn();
   
  }
  else if (option == 2)
  {
  //call SignUp() method
  Signup();
   
  }
  else if (option == 3)
  {
  //exit
  Environment.Exit(0);
  }
  else
  {
  Console.WriteLine("Error,choose another option from the menu!");
  }
  while (option <= 3) ;
  DisplayMenu();
   

  /*  option1 = MainMenu();
  if (option1 == 1)
  {
  //Read previous history method
  Console.WriteLine("Hello");

  }
  else if (option1 == 2)
  {
  //Enter new details
  }
  else if (option1 == 3)
  {
  //Show overall progress

  }
  else if (option1 == 4)
  {
  //EXIT
  Environment.Exit(0);
  }
  else
  {
  Console.WriteLine("Error,choose another option from the menu!");
  }
  option1 = MainMenu();
  while (option1 <= 4) ;
  MainMenu();
  */
  }  
  static int DisplayMenu()
  {
  int x = 0;
  Console.WriteLine("\n\n\n\n\n");
  Console.WriteLine("\t\t\t\t[1] Sign in");
  Console.WriteLine("\t\t\t\t[2] Sign up");
  Console.WriteLine("\t\t\t\t[3] Exit");   
  Console.WriteLine("Select from the menu:");

  x = int.Parse(Console.ReadLine());
  return x;
  }

  #region Code to sign up
  static void Signup()
  {
  string userID,password;
  Console.WriteLine("New Username: ");
  userID = Console.ReadLine();
  WriteToFile(userID,"UserID");
  Console.WriteLine("New Password: ");
  password = Console.ReadLine();
  WriteToFile(password,"Password");
  Console.WriteLine("You are registered");
  }

  static void SignIn()
  {

  string Username, Password;
  Console.WriteLine("Enter a Username: ");
  Username = Console.ReadLine();
  ReadFromFile(Username);
  Console.WriteLine("Enter a Password: ");
  Password = Console.ReadLine();
  ReadFromFile(Password);
  Console.WriteLine("Done.....");
  int option1 = MainMenu();
   


   
  }
  static int MainMenu()
  {
  Console.WriteLine("\n\n\n\n\n");
  Console.WriteLine("Select One Of The Options");
  Console.WriteLine("\t\t\t\t\t[1] Read Previous History ");
  Console.WriteLine("\t\t\t\t\t[2] Enter New Details ");
  Console.WriteLine("\t\t\t\t\t[3] Show Progress ");
  Console.WriteLine("\t\t\t\t\t[4] Sign Out ");
  int option1 = 0;
  option1 = int.Parse(Console.ReadLine());
  return option1;
   
  }

  #endregion
#region code to write a file
  static void WriteToFile(string content,string fname)
  {
  StreamWriter sw = null;
  sw = new StreamWriter(@"D:\"+ fname +".txt", true);
  sw.WriteLine(content);
  sw.Close();
  sw.Dispose();
   
  }
  #endregion

  #region code to read from file
  private static string ReadFromFile(string fname)
  {
  string content;
  StreamReader sr = null;
  try
  {
  sr = new StreamReader(@"D:\" + fname + ".txt");
  content = sr.ReadToEnd();
  return content;
  }
  catch (Exception ex)
  {
  //trow;
  Console.WriteLine("File does not exist");
  return null;
  }
  }
  #endregion
  }
}


   
 
   


Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

swat (35)
New York University

Anonymous
I was on a very tight deadline but thanks to Studypool I was able to deliver my assignment on time.

Anonymous
The tutor was pretty knowledgeable, efficient and polite. Great service!

Anonymous
Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4