C++ help for a beginner check writer

I am working on a check writer program that turns numbers into words. but I seem to have butchered my code. Any help at all would be appreciated. And if anyone knows how to tell the date and time please show me how to implement that into my program. at the moment I can't even get my code to compile.
Just poset my new 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<time.h>
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
using namespace std;

class Numbers 
{
 private:
 int number;
 static string one[];
 static string ten[];
 static string teen[];
 static string hundred[];
 static string thousand[];
 
public:
 Numbers();
 Numbers(int num){setNum(num);};
 void setNum(int num){number = num;};
 void print();
 };
 

string Numbers::one[] = {" " ,"one ", "two ", "three ", "four ", "five ", "six ",
                         "seven ", "eight ", "nine "} ;
 
string Numbers::teen[] = {" " ,"ten ","eleven ", "twelve " ,"thirteen ","fourteen ",
                         "fifteen ","sixteen ", "seventeen ","eighteen ","nineteen "};
 
string Numbers::ten[] = {" ","twenty ","thirty ","forty ","fifty ","sixty ","seventy "
                        ,"eighty ","ninety "};
 
string Numbers::hundred[] = {" ","one hundred ","two hundred ","three hundred ",
                            "four hundred ","five hundred ", "six hundred ",
                            "seven hundred ","eight hundred ","nine hundred "};
 
string Numbers::thousand[] = {" ","one thousand ","two thousand ","three thousand "
                             ,"four thousand ","five thousand ", "six thousand "
                             ,"seven thousand ","eight thousand ","nine thousand "};
                             
void Numbers::print() 
{
 if (number < 0)
 {number = -number;
 }
 
if (number == 0)
 {
 cout << "zero ";
 }
 
if (number >= 1000) 
{
 cout << thousand[number/1000];
 number %= 1000;
 }
 
if (number >= 100) 
{
 cout << hundred[number/100];
 number %= 100;
 }
 
if (number >= 20) 
{
 cout << ten[(number/10)-1];
 number %= 10;
 }
 
if (number >= 10 && number <= 19)
 {
 cout << teen[(number%10)+1];
 }
 
if (number > 0)
 {
 cout << one[number];
 }
 

 }
 




int main()
{
    double number;
    double value;                   
    char fname[50];
    char lname[50];        
    char again = 'y';       
    
    do {
        system ("cls");
        cout << "\n ****CHECK WRITER****";
        cout << endl;
        cout << "\nEnter Recipients Name: \n";
        cout << endl;
        cout << "Enter First Name: ";
        cin.getline(fname, 50);
        cout<< endl;
        cout << "Enter Last Name: ";
        cin.getline(lname, 50);
        
        cout << "\nEnter the Amount of the Check: ";
        cout << "(up to 99,999.99): $";
        cin >> value;      
                 

        cout << fixed << showpoint << setprecision(2); 
        cout << "--------------------------------------------------------------------\n";
        cout << setw(50) << right;
        cout << "\tPay to the order of:  " << fname  << " " << lname << "\t\t\t";
        cout << "$" << value << endl;
 
  if (value >= 0)
    {

        Numbers n(value);
         n.print();
    cout << endl;
    } 
        
        cout << "--------------------------------------------------------------------\n";
        cout << "\n Another check? (Y/N): ";
        cin >> again;
        cin.get();      
    } while (toupper(again) == 'Y');
    return 0;



 

system("pause");
}
Last edited on
Why are you trying to create your Numbers class inside a function?
So it's not supposed to go in the function? I apologise I'm terrible at this.
Now I feel dumb. @jlb thanks for pointing that out. I just looked it up and I was way off. :)
Last edited on
Alright I have posted my new code and it actually compiles! YAY! but it won't give me the words for the numbers. if anyone knows why please tell me. :)
Where do you ever use your class?
Topic archived. No new replies allowed.