-
October 12th, 2009, 04:57 PM
#1
C++ new line HELP
Hi guys can you guys help me cut this line into three lines because it is too long right now. I've tried using \n and endl but it ends up having errors when i compile it.
cout << "The average rainfall for "<<month1<<, "<<month2<<" and "<<month3<<" is: " << average << " inches"<< endl;
I need to seperate that into three lines so it displays like this.
The average rainfall for
January, February, and March
is: ____ inches.
-
October 12th, 2009, 05:00 PM
#2
Re: C++ new line HELP
You're missing a quote before the comma.
-
October 12th, 2009, 05:06 PM
#3
Re: C++ new line HELP
Originally Posted by Sabensohn70
I need to seperate that into three lines so it displays like this.
Can't you just split it up like,
cout << "The average rainfall for " << endl;
cout << month1 << ", " << month2 << " and " << month3 << endl;
cout << " is: " << average << " inches" << endl;
-
October 12th, 2009, 05:06 PM
#4
Re: C++ new line HELP
oh i didnt see that, but how do i seperate the line ?
-
October 12th, 2009, 05:09 PM
#5
Re: C++ new line HELP
hey nuzzle it didnt work when i did that.
-
October 12th, 2009, 05:11 PM
#6
Re: C++ new line HELP
Do you honestly think that "it didn't work" is useful diagnostic information? Details!
-
October 12th, 2009, 05:19 PM
#7
Re: C++ new line HELP
lol sorry it says
line 23: warning #2236-D:controlling expression is constant
cout << " << month1 <<"," << month2 <<" and " << month3 <<" endl;
^
line 23: warning #2236-D:controlling expression is constant
cout << " << month1 <<"," << month2 <<" and " << month3 <<" endl;
^
line 23: error #2065: expected a ";"
cout << " << month1 <<"," << month2 <<" and " << month3 <<" endl;
^
-
October 12th, 2009, 05:21 PM
#8
Re: C++ new line HELP
the arrows under the lines are actually under the parantheses before << month2, the parantheses before <<month3 and under the E in endl..
-
October 12th, 2009, 05:22 PM
#9
Re: C++ new line HELP
If you are wanting to print the " symbol, you must put the escape character in front of it.
Code:
cout << "\"" << month1 << "\"" << endl;
Did you not just straight copy/paste what nuzzle posted?
Last edited by jnmacd; October 12th, 2009 at 05:27 PM.
-
October 12th, 2009, 05:27 PM
#10
Re: C++ new line HELP
i dont want to display the " symbol, i just want it to say
The average rainfall for
January, February and March
is ____ inches.
-
October 12th, 2009, 05:29 PM
#11
Re: C++ new line HELP
Your errors show otherwise.
-
October 12th, 2009, 05:30 PM
#12
Re: C++ new line HELP
Originally Posted by Sabensohn70
hey nuzzle it didnt work when i did that.
Well, then you have some minor complication somewhere. If you comment out the problematic line, does the rest compile?
-
October 12th, 2009, 05:30 PM
#13
Re: C++ new line HELP
Well then, you've got a few extra quotes in that code.
-
October 12th, 2009, 06:05 PM
#14
Re: C++ new line HELP
okay i seperated it into three lines, now i am suppose to type it in two lines but have it show in one line when i compile it. how do i do this? so far i have.
cout << "The average rainfall for "<<month1<<, "<<month2<<" and "<<month3<<" is: " << average << " inches"<< endl;
I have to type that in 2 line so its shorter, but when I compile it can only show in one line.
-
October 12th, 2009, 06:06 PM
#15
Re: C++ new line HELP
Originally Posted by Lindley
Well then, you've got a few extra quotes in that code.
You mean me?
Well in that case I must've subconsciously corrected it on the fly.
I'm sorry for that. Will I be accused of helping with homework now?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|