Help me with C++

science

science rules
OP
Member
Joined
Jun 9, 2006
Messages
3,697
Trophies
1
Age
33
XP
1,249
Country
Canada
Hi. This is my C++ homework. I don't see whats wrong with it. What is wrong with it. Thanks

CODE(4) The following C++ program does not compile. Explain where the
ÂÂÂÂmistake is. If you correct the mistake, what would the
ÂÂÂÂoutput of the program be?

#include
using namespace std;

int main()
{
ÂÂcout
 

The Teej

Also known as The Tjalian
Former Staff
Joined
Jun 27, 2004
Messages
4,210
Trophies
0
Age
37
Location
England
Website
zeldapower.com
XP
653
Country
The output of the program will be:

"2 + 3 * 5 = 17"

I suppose you could technically say it would be "2 + 3 * 5 = 25", but I think I remember hearing somewhere is always does 2 + (3 * 5) unless (2 + 3) * 5 is specified. Someone correct me if I'm wrong, though
tongue.gif
 

ndstuff

Well-Known Member
Member
Joined
May 21, 2006
Messages
157
Trophies
0
Website
Visit site
XP
338
Country
Poland
CODE(4) The following C++ program does not compile. Explain where the
ÂÂÂÂmistake is. If you correct the mistake, what would the
ÂÂÂÂoutput of the program be?

#include
using namespace std;

int main()
{
ÂÂcout
 

science

science rules
OP
Member
Joined
Jun 9, 2006
Messages
3,697
Trophies
1
Age
33
XP
1,249
Country
Canada
Thanks guys, turns out I had already figured this out lastnight, but it was late, and I am sick so I forgot, but the answer was in my text file
tongue.gif
THANKS GUYS!
 

science

science rules
OP
Member
Joined
Jun 9, 2006
Messages
3,697
Trophies
1
Age
33
XP
1,249
Country
Canada
The Teej said:
The output of the program will be:

"2 + 3 * 5 = 17"

I suppose you could technically say it would be "2 + 3 * 5 = 25", but I think I remember hearing somewhere is always does 2 + (3 * 5) unless (2 + 3) * 5 is specified. Someone correct me if I'm wrong, though
tongue.gif

Nah, the answer is 17, you're right. The + has a lower precedence than the multiplication. It only does left to right if the precedence is the same
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    ColdBlitz @ ColdBlitz: the video title is "We Now Have A Touch Screen And OLED Modded Game Boy Color"