C++ Program Help

I'm having some trouble with my output file.

I want it to output such as this:
James Reed 1/13/2010
Pay to: Home Depot $45.30
Fourty Five and 30/100 dollars

but the numbers don't spell out in the last line.

Here's my code:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
void NumberSpell(int);
using namespace std;

int main()
{
	string date;
	string date2;
	string name;
	string firstName;
	string lastName;
	string amount;
	string Dollar;
	int Dol;
	string amountCent;
	int Cent;
	string Payee;
	string firstPayee;
	string lastPayee;

	ifstream inStream;
	inStream.open("database.txt");

	inStream >> date >> date2;
	cout << date  << " " << date2 << endl;

	inStream >> name >> firstName >> lastName;
	cout << name << " " << firstName << lastName << endl;

	inStream >> amount >> Dollar >> Dol;
	cout << amount << " " << Dollar << " " << Dol << endl;

	inStream >> amountCent >> Cent;
	cout << amountCent << " " << Cent << endl;

	inStream >> Payee >> firstPayee >> lastPayee;
	cout << Payee << " " << firstPayee << " " << lastPayee << endl;

	cin.get();

	inStream.close();

	ofstream outStream;
	outStream.open("check.txt");
	outStream << "Your check: \n";
	outStream << firstName << " " << lastName.append(13,' ') << date2 << endl;
	outStream << "Pay to: " << firstPayee << " " << lastPayee.append(5,' ')
	<< "$" << Dol << "." << Cent << endl; 
	NumberSpell(Dol); 
	outStream << " and " << Cent << "/100" << "\t" << "dollars";
	outStream.close();

	return 0;
}

void NumberSpell(int Dol)
{
  int tens = Dol/10;
  int ones = Dol%10;
  
  switch (tens)
  {
    case 1:
    switch (Dol)
    {
    case 10:  cout << "ten "; break;
    case 11:  cout << "eleven "; break;
    case 12:  cout << "twelve "; break;
    case 13:  cout << "thirteen "; break;
    case 14:  cout << "fourteen "; break;
    case 15:  cout << "fifteen "; break;
    case 16:  cout << "sixteen "; break;
    case 17:  cout << "seventeen "; break;
    case 18:  cout << "eighteen "; break;
    case 19:  cout << "nineteen "; break;
    }
    return;
    case 2:  cout << "twenty "; break;
    case 3:  cout << "thirty "; break;
    case 4:  cout << "fourty "; break;
    case 5:  cout << "fifty "; break;
    case 6:  cout << "sixty "; break;
    case 7:  cout << "seventy "; break;
    case 8:  cout << "eighty "; break;
    case 9:  cout << "ninety "; break;
  }
  
  switch (ones)
  {
    case 1:  cout << "one "; break;
    case 2:  cout << "two ";  break;
    case 3:  cout << "three "; break;
    case 4:  cout << "four "; break;
    case 5:  cout << "five "; break;
    case 6:  cout << "six "; break;
    case 7:  cout << "seven "; break;
    case 8:  cout << "eight "; break;
    case 9:  cout << "nine "; break;
  }
}
Please post a small sample of your input file.
This is my input file:

date: 1/13/2010
name: James Reed
amount, dollars: 45
cents: 30
payee: Home Depot
One issue is that you seem to have a return statement in your NumberSpell() function that probably shouldn't be there, line 80.

Also in main() you have a cin.get() that should probably be removed, line 42.

Also you do realize that your only printing the NumberSpell to the screen, not to your file? You may want to also pass a ostream& into that function so you can print to any stream, including cout.

void NumberSpell(std::ostream& out, int Dol)

Topic archived. No new replies allowed.