2 Replies - 13174 Views - Last Post: 01 February 2008 - 10:37 PM Rate Topic: -----

#1 RoverTCV8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-February 08

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

Post icon  Posted 01 February 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
Is This A Good Question/Topic? 0
  • +

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

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4313
  • View blog
  • Posts: 12,090
  • Joined: 18-April 07

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

Posted 01 February 2008 - 10:33 PM

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

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. :)
Was This Post Helpful? 0
  • +
  • -

#3 Jingle  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 317
  • Joined: 20-October 07

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

Posted 01 February 2008 - 10:37 PM

View PostRoverTCV8, on 1 Feb, 2008 - 10:15 PM, said:

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: 02 February 2008 - 06:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1