just general questions

1) How do I wrap lines? Example:
cout << "Hello blah blah blah ... too long... runs on in the window.. I want to
wrap it like this."<<endl<<"Continuing on blah blah." <<endl;

If I try it like I did above, the stuff in the second line isn't red like it's supposed to be when it's quoted.


2) How do I do if / else type stuff? For example, in my class, I have to write a program that inputs the length and width for two different rectangles and then tells the user which one is larger. I defined the variables as double, defined area1=length1*width1, and the same for area2, have the cout << "please input the length" ... width for second rectangle, all that stuff...

Now I need to have the program tell the user which one is larger. So if area1 > area to, then the program should say "Area 1 is larger." If they are equal the program should say they are equal...

What is the code to do that?

I only know how to do if else stuff. Since there are three possibilities, I don't know what to do.


---

Thanks !!! :)

1) There is not any built-in wrapping ability. You must insert the newlines yourself. Tbh, this isn't what you should be caring about anyway, let the user deal with it.

2) http://cplusplus.com/doc/tutorial/control/
Last edited on
I just want to so that it's easier for me to read... I don't want to read a single line that goes on and on and on... I know there's not a built-in wrapping ability --- I just want to know if I can wrap it manually.

Thanks for the link. ^_^
You need to use cout for each new line.

cout << "Blah blah blah.." << endl;
cout << "Continue your Blah'ing." << endl;
Any of these work:

1
2
3
std::cout << "Stuff on the first line ..." 
    << "Less than - less than stuff on the second line" 
    << std::endl;


or

1
2
3
std::cout << "Stuff on the first line ..." 
    "stuff on the second line without the less-than less-than" 
    << std::endl;


Double quoted strings can be split across multiple source lines in this way.

To answer your second question,

1
2
3
4
5
6
7
8
9
10
11
12
if( condition 1 )
{
     // handle condition 1
} 
else if( condition 2 )
{
    // handle condition 2
}
else /* neither condition 1 nor condition 2 */
{
    // handle all other conditions
}

Topic archived. No new replies allowed.