5 Replies - 608 Views - Last Post: 29 January 2010 - 12:04 AM Rate Topic: -----

#1 CaptKid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 16-August 09

help with this code

Posted 28 January 2010 - 05:26 PM

// Program asks user to enter password

// If password is not "home", "house" or "mouse"

// the user must re-enter the password

using System;

public class DebugFive2

{

public static void Main()

{

const string pass1 = home;

const string pass2 = house;

const string pass3 = mouse;

string password;

Console.Write("Please enter your password ");

password = Console.ReadLine();

while(password != pass1 || password != pass2 || password != pass3)

Console.WriteLine("Invalid password. Please enter again. ");

password = Console.ReadLine();

Console.WriteLine("Valid password");

}

} 


Is This A Good Question/Topic? 0
  • +

Replies To: help with this code

#2 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: help with this code

Posted 28 January 2010 - 05:35 PM

What errors are you getting?
When you create your project you should choose Console Application since its gonna be on console so you get the appropiate template.

Well another error is that when difining the string variable it should be done like
 const string pass1 = "home"


notice the quotes :P

Also you are missing an openning bracket for the while and i think your while loop is infinite :o

you should do a break if the pass is valid or something like that

EDIT: the condition on the while should be && not ||

This post has been edited by poncho4all: 28 January 2010 - 05:40 PM

Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: help with this code

Posted 28 January 2010 - 05:38 PM

What's the problem?
Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: help with this code

Posted 28 January 2010 - 06:16 PM

If you are only looking for a way how to improve your code, this might give you an idea:


static void Main(string[] args)
{
	string[] passwords = { "home", "house", "mouse" };
	string entered_password = string.Empty;


	while (!passwords.Contains(entered_password))
	{
		Console.Write("Please enter your password ");
		entered_password = Console.ReadLine();
	}

	Console.WriteLine("Valid password");
}

This post has been edited by FlashM: 28 January 2010 - 06:17 PM

Was This Post Helpful? 0
  • +
  • -

#5 coolguy200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-January 10

Re: help with this code

Posted 28 January 2010 - 09:57 PM

View PostFlashM, on 28 Jan, 2010 - 05:16 PM, said:

If you are only looking for a way how to improve your code, this might give you an idea:


static void Main(string[] args)
{
	string[] passwords = { "home", "house", "mouse" };
	string entered_password = string.Empty;


	while (!passwords.Contains(entered_password))
	{
		Console.Write("Please enter your password ");
		entered_password = Console.ReadLine();
	}

	Console.WriteLine("Valid password");
}

Cool idea is there a way once password entered it open a program for an example internet explore?
Was This Post Helpful? 0
  • +
  • -

#6 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: help with this code

Posted 29 January 2010 - 12:04 AM

System.Diagnostics.Process.Start("iexplore.exe");

Something like that I think :-)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1