CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Join Date
    Oct 2009
    Posts
    38

    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.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: C++ new line HELP

    You're missing a quote before the comma.

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: C++ new line HELP

    Quote Originally Posted by Sabensohn70 View Post
    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;

  4. #4
    Join Date
    Oct 2009
    Posts
    38

    Re: C++ new line HELP

    oh i didnt see that, but how do i seperate the line ?

  5. #5
    Join Date
    Oct 2009
    Posts
    38

    Re: C++ new line HELP

    hey nuzzle it didnt work when i did that.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: C++ new line HELP

    Do you honestly think that "it didn't work" is useful diagnostic information? Details!

  7. #7
    Join Date
    Oct 2009
    Posts
    38

    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;
    ^

  8. #8
    Join Date
    Oct 2009
    Posts
    38

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

  9. #9
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    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.

  10. #10
    Join Date
    Oct 2009
    Posts
    38

    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.

  11. #11
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: C++ new line HELP

    Your errors show otherwise.

  12. #12
    Join Date
    May 2009
    Posts
    2,413

    Re: C++ new line HELP

    Quote Originally Posted by Sabensohn70 View Post
    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?

  13. #13
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: C++ new line HELP

    Well then, you've got a few extra quotes in that code.

  14. #14
    Join Date
    Oct 2009
    Posts
    38

    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.

  15. #15
    Join Date
    May 2009
    Posts
    2,413

    Re: C++ new line HELP

    Quote Originally Posted by Lindley View Post
    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?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured