Code problem

Dec 2nd, 2013
SoccerBoss
Category:
Programming
Price: $15 USD

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


   
 
   


Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Carnegie Mellon University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
tinytim47
Dec 1st, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
Five Star Tutor
Nov 21st, 2016
" Outstanding Job!!!! "
mixedballz
Nov 17th, 2016
" excellent work as always thanks for the help "
lilmoe415
Nov 8th, 2016
" Thank you, Thank you, for top quality work, this is your guy!! "
darnay
Oct 26th, 2016
" The best tutor out there!!!! "
dontuwannaknow
Oct 17th, 2016
" Excellent work as always thanks so much "
SjSurvivor143
Oct 3rd, 2016
" Thanks for the help. "
Joemoe
Sep 20th, 2016
" <3 it, thanks for saving me time. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1823 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors