Thread: Output of program

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    16

    Output of program

    Hello,

    I executed this program and output was "C". Can someone expain why it was output and not "C++". Thanks.

    Code:
    int main(){
     float a = 0.7;
    if(a < 0.7)
         printf("c");
    else
        printf("c++");
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should make an attempt at explaining it yourself. Think of what you know about floating point number representations.
    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
    Registered User
    Join Date
    Apr 2010
    Posts
    16
    I have put this question for help. If you know answer tell it to me.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The answer is "yes"

    Seriously, read the homework guidelines. I already answered you in your other similiar homework thread.
    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

  5. #5
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Well. You can certainly see that school/uni/what-have-you has started up again.

  6. #6
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    Quote Originally Posted by Stuart Dickson View Post
    I have put this question for help. If you know answer tell it to me.
    SOoo demanding.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    What are the chances that "Stuart Dickson" is none other than sunil17 with a new username? Nearly the same MO.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Stuart Dickson View Post
    I have put this question for help. If you know answer tell it to me.
    Stuart, think about that big project, deadline hanging over your head, boss breathing down your neck ... and you have a problem you didn't bother to understand going in... You gonna run here and wait a couple of days for answers?

    Here's a hint.... Try to accurately represent any fraction in binary...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output of program
    By Stuart Dickson in forum C Programming
    Replies: 6
    Last Post: 09-04-2010, 07:10 AM
  2. Replies: 1
    Last Post: 05-29-2010, 05:24 AM
  3. calling an external program + capture output?
    By cyberfish in forum C++ Programming
    Replies: 4
    Last Post: 03-21-2008, 12:49 AM
  4. program looping with final output
    By hebali in forum C Programming
    Replies: 24
    Last Post: 02-28-2008, 10:58 AM
  5. Redirecting program output straight to an edit control
    By bennyandthejets in forum C++ Programming
    Replies: 5
    Last Post: 07-05-2004, 08:25 AM