Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Beginner programming question?

Beginner programming question?

Scheduled Pinned Locked Moved C#
questionhelptutoriallearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cmh623
    wrote on last edited by
    #1

    What am I doing wrong in this snippet of code? I can't seem to figure out how to make this work: 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"); } } Any help would be greatly appreciated

    C 1 Reply Last reply
    0
    • C cmh623

      What am I doing wrong in this snippet of code? I can't seem to figure out how to make this work: 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"); } } Any help would be greatly appreciated

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      First: you should get an compiler error with the consts - use const string pass1 = "home"; for example Second: in your while-loop you are just using the Writeline (no block) - use this: **{** Consoloe.WriteLine(.... password = .... **}** Then your problem is with the ORs (||): You iterate the while-loop as long the password is not pass1 OR not pass2 OR not pass3 and as pass1 != pass2 != pass3 you will satisfy this contition no matter what the input is - so just use && instead of || (substituting OR with AND) and it will work.

      C 1 Reply Last reply
      0
      • C CKnig

        First: you should get an compiler error with the consts - use const string pass1 = "home"; for example Second: in your while-loop you are just using the Writeline (no block) - use this: **{** Consoloe.WriteLine(.... password = .... **}** Then your problem is with the ORs (||): You iterate the while-loop as long the password is not pass1 OR not pass2 OR not pass3 and as pass1 != pass2 != pass3 you will satisfy this contition no matter what the input is - so just use && instead of || (substituting OR with AND) and it will work.

        C Offline
        C Offline
        cmh623
        wrote on last edited by
        #3

        Thanks CKnig, that definitely cleared things up for me. I appreciate your help!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups