Some help!!!!

This is a discussion on Some help!!!! within the C++ Programming forums, part of the General Programming Boards category; 1.How do I use the bit wise operator? 2. I have tried this code Code: #include<iostream> #include<conio.h> using namespace std; ...

  1. #1
    C++Pandit
    Join Date
    Jul 2008
    Posts
    49

    Arrow Some help!!!!

    1.How do I use the bit wise operator?
    2. I have tried this code
    Code:
    #include<iostream>
    #include<conio.h>
    using namespace std;
    main()
    {
          int a,b;
          cout<<"Enter a number";
          cin>>a;
          b=a^a;
          cout<<a<<" raised to "<<a<<" is "<<b;
          getch();
          }
    I use Dev-C++ Compiler.
    The above code compiles and the output is like this
    Enter a number 5
    5 raised to 5 is 0(wrong!!!!!)

    How do I raise a number to itself ?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    2. Use pow() from <math.h> (or std::pow() from <cmath>).
    ^ is bitwise XOR.

    1. There is no bit wise operator. There's bitwise AND, bitwise OR and bitwise XOR, and any tutorial can tell you how to use them. There's also left and right bitshift.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is no "raised to" operator in C. There is a "pow" function that takes two floating point values.

    Bitwise operators have been discussed many times on the forum, so I suggest you do a Search or look at the FAQ/Tutorial sections of the site.

    ^ is a bitwise operator, representing the "exclusive or" function, and 5 ^ 5 is indeed zero.

    If you still have SPECIFIC questions, please feel free to ask for further details.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    This code should not compile. Main must return int, always. No return type is an error in C++.
    And I'd also recommend getting rid of the Dev-c++ IDE because it screws up indentation something horribly.
    Here's a list of other free IDEs: http://cpwiki.sf.net/IDE
    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.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I never had any of the issues with Dev-C++ that people are always seeming to have nowadays. Though its quite an old piece of software, I do not know how come its still in such wide-spread use.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    It has come to my attention that by default, it creates unwanted indentation.
    For example, as above, it tends to do
    Code:
    int main()
    {
        // bla bla bla
        }
    Plus it's frustrating that it simply can't put the indentation level correctly many, many times. The best IDE that in my experience does this correctly and good is Visual Studio (Code::Blocks had some issues, too. I don't know if some settings can change that.)
    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.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I don't like how VC tries to change my switch case statements or how it screws up my indentation when I write classes the way I like

    Example:
    Code:
    class Oval :
      public virtual shape,
      public virtual drawable,
      public conical
    {
    
    };
    But that is a very quick backspace. Though its one more backspace than I think I should have to press.

    Quote Originally Posted by Elysia
    It has come to my attention that by default, it creates unwanted indentation.
    That is very poor on behalf of Dev-C++. Again I ask why its even still so widely used. It hasn't had a new version in nearly a decade.
    Last edited by master5001; 10-14-2008 at 01:26 PM.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Wait, how does VC screw up and how did Dev-C++ screw up? I'm sorry, your post didn't seem very clear (it seemed to mix the two together?).
    I know VC isn't perfect either (tends to so some things I don't like), but overall, in my opinion, it's better than other IDEs.
    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.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok there we go. Sorry about that. Run-on thoughts there -_- Just re-read the post now.

    I agree with your thoughts on MSVC. The overall impressions of it to me are that though it does a few annoying things, those annoying things are easily fixed.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Ah, it's much clearer now.
    So it creates an extra tab or indentation when you write classes (deriving from other classes), is that it?
    And I also suppose you're not entirely happy about how it puts the cases in switches at the same level as the { and } (I don't like it)?
    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.

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah those are my only real gripes. But to be honest, since I use MSVC++ a lot I am so used to fixing its indenting without even thinking about it, that the issue is mostly trivial.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    I see, I see. Very informative of you. Thank you.
    I have a couple of gripes myself.
    Everything beginning with "#" is automatically moved to no indentation level.
    Cases are on the same level as the switch keyword itself.
    VS fails epically when splitting long lines into multiple lines with ( and ) here and there (like I did with cpjust's code in a post). Although I can't say I blame the IDE for it. Must be difficult to know when to choose a different rule. I have to manually indent those.
    ...And that's all I can think of right now.
    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.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,159
    Everything beginning with "#" is automatically moved to no indentation level.
    That does make sense though, since macros do not obey scope.

    Cases are on the same level as the switch keyword itself.
    This is one of the things I like about Visual Studio
    The reason is that it seems more consistent when I replace an if/else chain with a switch.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Elysia View Post
    Everything beginning with "#" is automatically moved to no indentation level.
    Oh dear lord, yes! That is amazingly irritating. There are a few other issues that have come up periodically. But there are more. Once you get used to it doing something one way, and needing to immediately undo what it did, it becomes second nature and harder to remember which things annoy you since you are so used to just automatically fixing them.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Quote Originally Posted by laserlight View Post
    That does make sense though, since macros do not obey scope.
    They don't, generally, but if you want to nest them, you don't want them all to end up on the same indentation level...
    But Visual Studio fixes the indentation level each time you hit enter, just typing # destroys that. So it becomes a chore to do things like:
    Code:
    #if x
        #if y
            ...
    This is one of the things I like about Visual Studio
    The reason is that it seems more consistent when I replace an if/else chain with a switch.
    Can't actually see how you like that

    Quote Originally Posted by master5001 View Post
    Oh dear lord, yes! That is amazingly irritating. There are a few other issues that have come up periodically. But there are more. Once you get used to it doing something one way, and needing to immediately undo what it did, it becomes second nature and harder to remember which things annoy you since you are so used to just automatically fixing them.
    Indeed. It does tend to become second nature...
    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.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21