Help with Spacing Issue

How can I get my spacing to look like example? Specifically, how do I get "Date," "$ amt.00," and "ahFRST ahLAST" alligned on the right. The "$ amt.00" moves depending on how long the pyFRST and pyLST are:

Example:

ahFRST ahLAST
STREET ADDRESS
CITY, STATE, ZIP Date: mm/dd/yy

Pay to the Order of: pyFRST pyLST $ amt.00

"amt in words" and no/100s Dollars

BANK OF CSC5

FOR: GOTTA PAY THE RENT ahFRST ahLAST



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

string ones[]={"","One","Two","Three","Four","Five","Six",
                 "Seven","Eight","Nine","Ten","Eleven",
                 "Twelve","Thirteen","Fourteen","Fifteen",
                 "Sixteen","Seventeen","Eighteen","Nineteen",};
string tens[]={"Twenty","Thirty","Forty","Fifty","Sixty",
                 "Seventy","Eighty","Ninety",};
string hundred="Hundred";
string NUM_WORD(int num){
    if ((num<1)||(num>999)){
        return "The check value you entered is not between $1 and $999.\n";
    }else if (num>=100){
        int first=num/100;
        return ones[first] + " " + hundred + " " + NUM_WORD(num - first * 100);
    }else if (num >= 20){
        int leftDigit = num / 10;
        int rightDigit = num % 10;
        return tens[leftDigit - 2] + " " + ones[rightDigit];
    }else (num >= 0);{
        return ones[num];
    }
}
int main()
{
    string date;
    string pyFRST;
    string pyLST;
    float amt=0.00;
    string ahFRST;
    string ahLST;
    
    cout<<"Please enter the details of your check below.\n";
    cout<<"Date (mm/dd/yy): ";
    cin>>date;
    cout<<"Payee (First Last): ";
    cin>>pyFRST>>pyLST;
    cout<<"Enter $ amount of check ($1-$999, no cents): ";
    cin>>amt;
    cout<<"Your Name (First Last): ";
    cin>>ahFRST>>ahLST;
    
    cout<<endl;
    cout<<endl;
    cout<<ahFRST<<" "<<ahLST<<endl;
    cout<<"STREET ADDRESS\n";
    cout<<"CITY, STATE, ZIP                              "<<"Date:    "<<date<<endl;
    cout<<endl;
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"Pay to the Order of:  "<<pyFRST<<" "<<pyLST<<setw(20)<<"$ "<<amt<<endl;
    cout<<endl;
    cout<<NUM_WORD(amt)<<" and no/100s Dollars\n";
    cout<<endl;
    cout<<"BANK OF CSC5\n";
    cout<<endl;
    cout<<"FOR:  GOTTA PAY THE RENT                      "<<ahFRST<<" "<<ahLST<<endl;
    
    return 0;
}
You might want to read more on c++ manipulators
http://www.cplusplus.com/reference/iomanip/setw/
Last edited on
Topic archived. No new replies allowed.