Thread: whats wrong with this code?

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    186

    whats wrong with this code?

    stupid..sorry
    Last edited by jcafaro10; 08-06-2007 at 08:20 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Is this a "find five faults"?

    1. You are using "ans", whilst the parameter do Draft:raft is called "nans".

    2. You are using a bitwise or ('|') rather than a logical or ('||').

    3. You will most likely encounter an infinite loop should the "ans" be "y" or "n". And of course, since the while-loop isn't entered if you DON'T enter a "y" or "n" string, the final else is pretty pointless, don't you think. The whole while-loop itself can be removed and aside from not creating an endless loop in your Draft constructor, you'd be fine.

    4. I think you'll find that your string isn't containing exactly what you expect - what it contains is a different question.

    5. Probably don't need a "cout << endl;" after a cin, as hitting enter on the "cin" will make a newline to the console in itself.

    --
    Mats

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Do not delete the original post.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    186
    sry, when I had deleted it, there weren't any answers up so I guess he musta been typing it. What a bitwise operator mean? Whats the difference between | and ||

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Logical operators evaluate the statement to true or false. Bitwise operators do basically the same thing (if there's a logical counterpart), but on a bit-by-bit basis, resulting in a numerical result.

    (If you're on Windows, you may try the OR'ing some pairs of values entered as binary on the calculator.)
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM