Need help fully understanding variables | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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

26th Mar 2019, 3:59 AM
Clara Bahoya
7 Antworten
+ 1
Something like this? cout << "What is my first variable? \n\n";
26th Mar 2019, 4:32 AM
Diego
Diego - avatar
+ 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.
26th Mar 2019, 4:41 AM
Vlad Serbu
Vlad Serbu - avatar
+ 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).
26th Mar 2019, 4:56 AM
Diego
Diego - avatar
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?
26th Mar 2019, 4:48 AM
Clara Bahoya
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 “
26th Mar 2019, 4:56 AM
Clara Bahoya
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
26th Mar 2019, 4:59 AM
Clara Bahoya
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.
26th Mar 2019, 7:09 AM
Vlad Serbu
Vlad Serbu - avatar