Please help with "check" code

Ok so I have to make code print this like a check.

date: 2/13/2014
name: William Schmidt
amount, dollars: 23
cents: 30
payee: Office Max


your check:

William Schmidt 2/13/2014
pay to: Office Max $23.30
twenty three and 30/100 dollars
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
#include <iostream>
#include <string>

using namespace std;

int main(){
	string date;
	string name;
	int dollars;
	int cents;
	string payee;
	
	cout << "Input check information:";
	cout << endl;
	cout << "date: ";
	getline(cin, date);
	cout << "name: ";
	getline(cin, name);
	cout << "amount in dollars:";
	cin >> dollars;
	cout << "amount in cents:";
	cin >> cents;
	cout << "Payee:";
	getline(cin, payee);
	getline(cin, payee);
	cout << "Your check:";
	cout << endl;

	string s1;
	int pay;

	s1 = name;
	pay = 50 - s1.length();
	s1.append(pay, ' ');
	s1.append(date);
	cout << s1 << endl;
	 
	string s2;

	s2 = "pay to:", payee;
	pay = 50 - s2.length();
	s2.append(' ', dollars);
	s2.append('.', cents);
	s2.append(pay, ' ');
	cout << s2 << endl;  // fix 

	string s3;

	s3 = "twenty three and 30/100";
	pay = 50 - s3.length();
	s3.append(pay, ' ');
	s3.append("dollars");
	cout << s3 << endl;
}[code]


Here is my code the // fix is were the problem is at, for some reason it shoots some strange symbols, also I cant seem to make it do pay to: along with the payee.
s2.append(' ', dollars)
The first argument to append here is the number of characters to append. The second argument is the character to append. ' ' is not a count, and dollars is not a character.

To append to a string use +=, as in: s2 += to_string(dollars);
To convert to a string use to_string, as shown immediately above.

s2 = "pay to:", payee;
is equivalent to:
1
2
    s2 = "pay to:";
    payee;
Ah thank you I fixed the code the only problem now is it wont let me put a dollar sign in front of dollar and . for cents. I kept getting an error when I try saying I overloaded the function.

1
2
3
4
5
6
7
8
string s2;

	s2 = "pay to:" + payee;
	pay = 50 - s2.length();
	s2.append(pay, ' ');
	s2 += to_string(dollars);
	s2 += to_string(cents);
	cout << s2 << endl;  // fix  


So it puts out 2330
I need it $23.30
Do you know the argument to use?
opps never mind I figured it out thank you very much!
Topic archived. No new replies allowed.