Code problem

User Generated

zeqrib

Programming

Description

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
  }
}


   
 
   


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer


Anonymous
Just the thing I needed, saved me a lot of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags