How to create more space between two lines of data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gonzalo
    New Member
    • Apr 2010
    • 1

    #1

    How to create more space between two lines of data

    take a look at the code.

    when i ask for an input i like it to be a space between the question and the persons answer.

    so i us \t to create a tab.

    but when i run the program it gives me different spaces.
    like this:
    Click image for larger version

Name:	wrong space.jpg
Views:	1
Size:	18.1 KB
ID:	5416103



    Code:
    #include <iostream.h>
    #include <string.h>
    #include <iomanip.h>
    main()
    
    {
          char phone_number[] = "(000) 000-0000"; 
          char zip_code[11];
          char address[30];
          char name[21];
          char city[21];
          char state[20];
          
          cout << "Please enter your name:\t";
          cin.get(name,21);
          cin.ignore(80,'\n');
          cout <<"Please enter your address:\t";
          cin.get(address,30);
          cin.ignore(80,'\n');
          cout << "please enter your city:\t";
          cin.get(city,21);
          cin.ignore(80,'\n');
          cout << "please enter your state:\t";
          cin.get(state,20);
          cin.ignore(80,'\n');
          cout << "please enter your ZIP Code:\t";
          cin.get(zip_code,11);
          cin.ignore(80,'\n');
          cout << "please enter your phone number:\t";
          cin.get(phone_number,20);
          cin.ignore(80,'\n');
          
          cout << name <<'\n';
          cout << address <<'\n';
          cout << city << setw(10)<< state << setw(10)<< zip_code <<'\n';
          cout << phone_number<<endl;
          
         system("pause");
          return 0;
    }
    Last edited by Banfa; May 25 '10, 01:52 PM. Reason: Added [code]...[/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Remove the tab characters then:

    Either make all your strings the same length by padding with spaces.

    Or use the setw (set width) io manipulator to set the field width of the output text, you might also need to use the left io manipulator o get the text at the right end of the field.

    BTW
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <iomanip.h>
    These are the pre-standardisation (released in 1998) headers you should use
    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    For a modern standards compliant compiler.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      The tab stops on your output device bear no relation to the tab stops in the editor you use to create the source code.

      Comment

      Working...