+ 1
Need help fully understanding variables
I have a question! Can someone help me figure out something? My code is working like I want it but I was just curious to know whether I can twist it a little bit. Check line 14 or 17. Is there a way for me to jump to the next line (I guess here next two lines) without writing <<endl <<endl; OR <<â\nâ <<endl; ??? I want the same output/format for ALL my lines BUT I wanna know if there is something I can put in the â â to jump to the next line? I tried â... \nâ then ONLY ONE <<endl; but it didnât work like I want to. If you understand my concern, please let me know if what I did is the only way to write that code. Thanks in advance! https://code.sololearn.com/cQ136sFktW8x/?ref=app
7 RĂ©ponses
+ 1
Something like this?
cout << "What is my first variable? \n\n";
+ 1
A computer doesn't view a block of text as multiple lines. Instead, for it, it's only one "line". When it draws it on the screen it uses the '\n' character to know when to go the next line. endl just puts an '\n', and does some other stuff you don't need to worry about.
+ 1
Clara Bahoya Not an expert on C++ but I think there's no way to do what you want to do (please anyone prove me wrong).
0
I used a phone to write that code so Iâm not sure if weâre checking the same lines.
Diego I am asking about the answer, not the question. For the question I know that can be done but it doesnât seem to work the same way with the answer âYour first variable is: â
If I put what you said I think it will move my number to the next line? Not so sure but I will give it a try and update you!
Vlad Serbu do you mean what I did is the only way to display that?
0
I am wondering if there is a way to output âYour next variable is: 18â by adding something after â... is: â that will make it jump to the next line without displaying âYour next variable is:
18 â
0
Diego thank you for the help! I was thinking the same and just wanted to make sure that Iâm not mixing up the concepts
0
Clara Bahoya You can just do cout << "Your first variable is: " << number; if you want to print it on the same line. But that is what you did in your code. I'm afraid I don't understand what you want to do.