Thread: simple program

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    simple program

    [hi all, i am new to this and not very sure if the code i write is correct..anw, my com doesnt have Visual C++ so i cant complie and check..must wait till i return school on monday.. i have written a code and it sound correct to me...would really be thankful if anyone could just take a look at it and help me check if i have made any mistakes

    the below is a code to use the bitwise AND operation (ea12 ∩ 1201)

    Code:
    #include <stdio.h>
    #define AND &&
    
    int main(void)
    
    { float output;
    
    output = 0xea12 && 0X1201 ;
    printf("The output is %f", output );
    
    return0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i am new to this and not very sure if the code i write is correct..anw, my com doesnt have Visual C++ so i cant complie and check..must wait till i return school on monday.. i have written a code and it sound correct to me...would really be thankful if anyone could just take a look at it and help me check if i have made any mistakes
    You can download and use Microsoft Visual C++ 2008 Express for free. Asking people to help you compile and test online would be rather tedious, not to mention slow. Also, you would lose out on the practice of using the compiler and IDE yourself, which may be a factor if you have to compile and debug during a lab test.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Code:
    output = 0xea12 && 0X1201 ;
    When you get to class on Monday, I would look at this line in particular.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    thanks alot!!! anw, wanted to know if the code sounds logical...thanks laserlight =)

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    JDGARX... this line is wrong?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    wanted to know if the code sounds logical
    Well, why is output a float instead of an int (or _Bool)?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    oh, okie noted...actually i not sure if i shd put float or int..

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    actually i not sure if i shd put float or int
    What is the difference between float and int, and what are the kind of values that the expression (x && y) evaluates to?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Mar 2008
    Posts
    11
    the output shd be an int...yup. so i change accordingly. thanks alot =)

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Remember to update the format specifier for printf()
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM