943,685 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 745
  • C++ RSS
Apr 11th, 2009
0

bug fix

Expand Post »
Hi all,
what is the bug in the following code:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. int main()
  4. {
  5. string str = "Hello World!"
  6. cout << str << endl;
  7. cout << float x = 5.0f * str << endl;
  8. int 65Num = 65;
  9. cout << "65Num = " << 65Num << endl;
  10. }
Last edited by Ancient Dragon; Apr 11th, 2009 at 10:28 am. Reason: add code tags
Similar Threads
Reputation Points: 3
Solved Threads: 0
Light Poster
iammfa is offline Offline
47 posts
since Apr 2009
Apr 11th, 2009
1

Re: bug fix

Click to Expand / Collapse  Quote originally posted by iammfa ...
Hi all,
what is the bug in the following code:

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. int main()
  4. {
  5. string str = "Hello World!"
  6. cout << str << endl;
  7. cout << float x = 5.0f * str << endl;
  8. int 65Num = 65;
  9. cout << "65Num = " << 65Num << endl;
  10. }
There are a lot of "bugs" in your code.
Frist, you miss the using namespace std; line before the main() function, so the compiler might not recognize cout and string .
You also missed a semicolon after "Hello World!" .
Another thing is that you can't declare variables inside cout , so you should take float x = 5.0f * str outside cout . The multiplication operation of a float type and string type is not even declared, so float x = 5.0f * str has no meaning. The variable 65Num has an "illegal" name - variables' names cannot begin with a digit.
Reputation Points: 42
Solved Threads: 13
Junior Poster in Training
unbeatable0 is offline Offline
90 posts
since Sep 2008
Apr 11th, 2009
0

Re: bug fix

What a crap this code is ?
60% of your code is full of bugs ...

Read your textbook first !

By the way, in future post using code tags ...
Last edited by tux4life; Apr 11th, 2009 at 9:38 am.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 11th, 2009
0

Re: bug fix

sorry, this not my code, it was an exercise want me to correct bugs, thanks "unbeatable0" for helping.
Reputation Points: 3
Solved Threads: 0
Light Poster
iammfa is offline Offline
47 posts
since Apr 2009
Apr 11th, 2009
0

Re: bug fix

Click to Expand / Collapse  Quote originally posted by tux4life ...
What a crap this code is ?
60% of your code is full of bugs ...

Read your textbook first !

By the way, in future post using code tags ...
Looks a lot like my code too
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Apr 11th, 2009
0

Re: bug fix

lol thats some pretty basic bugs
Reputation Points: 10
Solved Threads: 5
Newbie Poster
stumpy798 is offline Offline
18 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help With Final Output
Next Thread in C++ Forum Timeline: destruction of a global variable?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC