bug fix

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 20
Reputation: iammfa has a little shameless behaviour in the past 
Solved Threads: 0
iammfa iammfa is offline Offline
Newbie Poster

bug fix

 
0
  #1
Apr 11th, 2009
Hi all,
what is the bug in the following code:
  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: bug fix

 
1
  #2
Apr 11th, 2009
Originally Posted by iammfa View Post
Hi all,
what is the bug in the following code:

  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: bug fix

 
0
  #3
Apr 11th, 2009
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.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 20
Reputation: iammfa has a little shameless behaviour in the past 
Solved Threads: 0
iammfa iammfa is offline Offline
Newbie Poster

Re: bug fix

 
0
  #4
Apr 11th, 2009
sorry, this not my code, it was an exercise want me to correct bugs, thanks "unbeatable0" for helping.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: bug fix

 
0
  #5
Apr 11th, 2009
Originally Posted by tux4life View Post
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
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: stumpy798 is an unknown quantity at this point 
Solved Threads: 4
stumpy798 stumpy798 is offline Offline
Newbie Poster

Re: bug fix

 
0
  #6
Apr 11th, 2009
lol thats some pretty basic bugs
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC