0

Hi all,
what is the bug in the following code:

#include <iostream> 
#include <string>
int main()
{
string str = "Hello World!"
cout << str << endl;
cout << float x = 5.0f * str << endl;
int 65Num = 65;
cout << "65Num = " << 65Num << endl;
}
5
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by stephen.id
1

Hi all,
what is the bug in the following code:

#include <iostream> 
#include <string>
int main()
{
string str = "Hello World!"
cout << str << endl;
cout << float x = 5.0f * str << endl;
int 65Num = 65;
cout << "65Num = " << 65Num << endl;
}

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.

Votes + Comments
Nice explanation ! :)
0

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 ...

0

sorry, this not my code, it was an exercise want me to correct bugs, thanks "unbeatable0" for helping.

0

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 :)

0

lol thats some pretty basic bugs

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.