3 Replies - 1102 Views - Last Post: 24 August 2001 - 02:58 PM Rate Topic: -----

#1 Jayson47  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-August 01

ITS ALL JUMBLED UP!

Posted 24 August 2001 - 09:10 AM

I'm writing a program where my output to the screen needs to be lined up nice and neat. But the length of the output depends on the user. For example,
cout<<"************************************************************
";
cout<<"*                                                          *
";
cout<<"*   John Doe's Auto Repair            #"<<check<<"  August 31,2001   *
";
cout<<"*   47 Coughsputterchoke Rd                                *
";
cout<<"*   Rio Rancho, NM 87124                                   *
";
cout<<"*                                                          *
";
cout<<"*   Pay to the order of: "<<name<< "              *
";
cout<<"*   Social Security #: "<<ssn<<"                           *
";
cout<<"*                                                          *
";
cout<<"*                                                          *
";
cout<<"*   The amount of: ";

This is the format in which the output needs to be in, but i cant seem to set it so names of different lengths will work and stay aligned. Help would be appreiciated.

Is This A Good Question/Topic? 0
  • +

Replies To: ITS ALL JUMBLED UP!

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: ITS ALL JUMBLED UP!

Posted 24 August 2001 - 09:25 AM

#Moderation Mode

And magically it's moved to the C++ forum, thanks...

Moved here

Was This Post Helpful? 0
  • +
  • -

#3 Null and Void  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 29-April 01

Re: ITS ALL JUMBLED UP!

Posted 24 August 2001 - 01:06 PM

One way:
Use strlen to get the length of the input (and to-be output) strings, then loop to output the needed number of spaces, then the other characters.

Another way:
Find a "set cursor x,y" function for whatever console system you're using (there isn't a standard one). Then just jump to the end of the row after you output the string.

Another way:
Use something like this to make the output a set width:
printf("%25s",AStringGoesHere);

25 is the number of spaces that the output should be forced to take.

Was This Post Helpful? 0
  • +
  • -

#4 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: ITS ALL JUMBLED UP!

Posted 24 August 2001 - 02:58 PM

use setw it won't get it perfect but play around with it until it looks good.

And by the way if you don't know what setw is look it up in your text book. im pretty sure you are from the clas if not write back and i will tell you.

Also i would take away the end *'s because the will not come out aligned.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1