Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,045 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,651 people online right now. Registration is fast and FREE... Join Now!




How to place a space in the cout line for 3 different numbers?

 
Reply to this topicStart new topic

How to place a space in the cout line for 3 different numbers?, What is the correct way of adding spaces?

RoverTCV8
1 Feb, 2008 - 09:15 PM
Post #1

New D.I.C Head
*

Joined: 1 Feb, 2008
Posts: 11


My Contributions
Hello,
I am new to this as this is my new experience with C++. I have written about a 75 lines of code and is fine howeever, after my "double line,
I have this:

cout << "Input three different numbers: \b";

What I need to know is how to get 3 numbers to post on the same line with a space between them?
Thanks
David
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How To Place A Space In The Cout Line For 3 Different Numbers?
1 Feb, 2008 - 09:33 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well if you are asking the user to input the numbers, they are the one that has to add the spaces. If you just want to add spaces between numbers, you can simply use " " (that is double quotes with a space in the middle).

CODE

cout << "Input three numbers: " << number1 << " " << number2 << " " << number3 << endl;


This would print three numbers contained in the three variables onto the line. But if you are asking for them to input the numbers, the user has to do that and you have to parse their response to fetch the three numbers.

I hope that makes sense and that I am understanding you correctly. smile.gif
User is online!Profile CardPM
+Quote Post

Jingle
RE: How To Place A Space In The Cout Line For 3 Different Numbers?
1 Feb, 2008 - 09:37 PM
Post #3

D.I.C Regular
***

Joined: 20 Oct, 2007
Posts: 250


My Contributions
QUOTE(RoverTCV8 @ 1 Feb, 2008 - 10:15 PM) *

Hello,
I am new to this as this is my new experience with C++. I have written about a 75 lines of code and is fine howeever, after my "double line,
I have this:

cout << "Input three different numbers: \b";

What I need to know is how to get 3 numbers to post on the same line with a space between them?
Thanks
David

do you mean that you want to print 3 numbers on the same line but with spaces between them?
or that you want spaces on the cin>> while your typing it in.

the first is easy there are multiple ways of doing it the latter is not so easy and i have no clue how it would be done.

cout<<2<<' '<<3<<' '<<4;
that is one way of doing it.

looks like Martyr beat me to it

This post has been edited by Jingle: 2 Feb, 2008 - 05:12 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 10:05PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month