Thread: Need help because i am a noob!

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    10

    Need help because i am a noob!

    I am starting to learn c++ from the book "Jumping into c++" and wonder how to solve the second practice problem on chapter 4. It says "Implement a simple "password" system that takes a password in the form of a number. Make itso that either of two numbers is valid, but use only one if statement to do the check."

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    with which part are you having trouble?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    I feel really dumb because I don't really understand the question. Or rather the "Make it so that either of two numbers is valid" part :S

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    Have you read about logical operators yet?

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    No I have just passed If statements

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    I'm not sure how you'd solve this without logical operators.

    ...I don't really understand the question. Or rather the "Make it so that either of two numbers is valid" part
    Imagine you could pick two different passwords to log into this site. Then, as long as you enter either one of those passwords, you'd be able to sign on (instead of just a single password). Not a practical real-world scenario, but good for purposes of practice.

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    I am sorry, I have read about the logical operators. I tested to do something like this:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int password;
    
        cout << "Please enter the password: ";
        cin >> password;
    
        if ( password == ( 1337 || 1338) )
        {
            cout << "Corerct! Access granted!\n";
        }
        else
        {
            cout << "Wrong! Access denied!";
        }
    }
    But it seems like it doesn't work :/

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    I noticed a missed space between 1338 and the ")" but it doesn't affect anything

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    You have the idea, but the syntax is wrong. I'd recommend reviewing that section in your book again.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,664
    > if ( password == ( 1337 || 1338) )
    Try
    if ( (password == 1337) || (password == 1338) )

    There is no "compare this with a list of things" operator in C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Apr 2013
    Posts
    10
    Okay, i'm going to read about that again, thank you so much for your time and help

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Salem View Post
    ...There is no "compare this with a list of things" operator in C.
    Or C++, as it is in this case
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob to C need a little help!!!
    By sk8harddiefast in forum C Programming
    Replies: 8
    Last Post: 02-27-2010, 02:47 PM
  2. need some noob help
    By klmdb in forum C Programming
    Replies: 3
    Last Post: 01-16-2010, 11:03 AM
  3. need some C noob help
    By klmdb in forum C Programming
    Replies: 3
    Last Post: 12-20-2009, 02:37 PM
  4. Noob needs help :)
    By Cursius in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2009, 04:19 PM
  5. noob
    By valthyx in forum C Programming
    Replies: 3
    Last Post: 07-21-2008, 02:23 PM

Tags for this Thread