Thread: beginner help

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    beginner help

    i have this program when the user enter a number for example 7 it is sup

    Code:
    #include <iostream>
    
    using namespace std;
    int main()
    {
        
        int choice;
        
        cout<<"pick choice"<<endl;
        cin>>choice;
        
        if(choice>>1&&choice<<5)
        {
                                
        cout<<"hi";
        
        }
        else
        cout<<"worng";
        
        cin.sync();
        cin.get();
    
    }

  2. #2
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    Code:
    if(choice>>1&&choice<<5)
    You might want to add some spaces there, just for readability.
    Code:
    if (choice >> 1 && choice << 5)
    Now, lets see what it actually does... Oh, wait, are you using bitwise shift operators instead of comparing the values? Yup. Now, how would you go about correcting that?

    Oh, and you spelled it "wrong". ^^

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    if i knew i wouldnt be asking

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Well perhaps you were just given a clue as to what you might need to find out about, by yourself, in order to correct the issue.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    68
    if(choice>>1&&choice<<5)



    is incorrect

    The >> operator is a bitshift.

    You are writing this

    shift choice to the right by one bit and shift choice to the left by 5 bits. If those two values are both true, then execute the following code

    You meant to write a SINGLE > not a double..

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    thank

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ADO.NET in VS2008 or gdi+ (beginner question)
    By robgar in forum C# Programming
    Replies: 3
    Last Post: 10-04-2009, 02:40 AM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM