Help writing a program that asks the user the check information and prints the check?

need to write a program that inputs the following:

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

and outputs it like so:
William Schmidt 2/23/2010
pay to: Office Max $23.30
twenty three and 30/100 dollars

This is the code I've created to input and output dollar amounts but it does it all in one input and I believe it needs to be two separate ones. Plus, I feel like the code is a bit too long. That's not my only problem, but here it is:

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;

#include <cmath>


int main()
{
const char *onesTeens[ 20 ] = { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen" };

const char *tens[ 10 ] = { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty",
"Seventy", "Eighty", "Ninety" }; // I added "zero" and "ten" to make calling elements easier. They aren't used.


float amount;
int total;

int dollars, cents, num;


cout << "Please enter an amount (000000.00)(-1 to end): ";
cin >> amount;

while( amount != -1 )
{
total = (int) ceil( amount * 100 ); // Float into int
dollars = total / 100;
cents = total % 100;


cout << "\n";

if( dollars >= 100000 ){ // For range 999,999 to 100,000
num = dollars / 100000;
cout << onesTeens[ num ] << " Hundred ";

if( ( dollars / 10000 ) % 10 == 0 && // In case the 2nd and 3rd digits are zeros
( dollars / 1000 ) % 10 == 0 )
cout << "Thousand ";

dollars -= num * 100000; }

if( dollars >= 20000 ){ // For range 99,999 to 20,000
num = dollars / 10000;
cout << tens[ num ] << " " ;

if( ( dollars / 1000 ) % 10 == 0 ) // In case the 3rd digit is a zero.
cout << "Thousand ";

dollars -= num * 10000; }

if( dollars >= 10000 ){ // For range 19,000 to 10,000
num = dollars / 1000;
cout << onesTeens[ num ] << " Thousand ";
dollars -= num * 1000; }


if( dollars >= 1000 ){ // For range 9,999 to 1,000
num = dollars / 1000;
cout << onesTeens[ num ] << " Thousand ";
dollars -= num * 1000; }

if( dollars >= 100 ){ // For range 999 to 100
num = dollars / 100;
cout << onesTeens[ num ] << " Hundred ";
dollars -= num * 100; }

if( dollars >= 20 ){ // For range 99 to 20
num = dollars / 10;
cout << tens[ num ] << " ";
dollars -= num * 10; }

if( dollars > 0 ){ // For range 19 to 1
num = dollars;
cout << onesTeens[ num ]; }

cout << " Dollars and " << cents << "/100" << endl;


cout << "\n\nPlease enter an amount (000000.00)(-1 to end): ";
cin >> amount;
}
cout << "\nThank you for using this program.\n" << endl;

return 0;
}


Also, I really don't know how to go about getting the other things to input and output in the form required. Help please? Thank you!
Last edited on
closed account (3qX21hU5)
Can help you with you with getting the other things to input and output in the format you want. Basically you just use the getline(cin,name).

Also use the source code format when pasting code it makes it alot easier to read
Topic archived. No new replies allowed.