Please Help newb writing check writer

I have been writing this program for two weeks and have decided I'm terrible at programming. This assignment is way over due ,but I really want to finish it any help will be appreciated. My current issues are....

* the calculations function is not working from 0 to 10 thousand. I need help with the logic and syntax.

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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
#include<fstream>
#include<cstring>
#include<conio.h> //getch            //getch is not used in this program


using namespace std;

string calculations(double);
void LoadCharAmt();

string charAmt[30]; //Global array

int main()
{
	

//char UL = 201, UR = 187, LL = 200, LR = 188, VB = 186;
    double amountofCheck;
// char[] maybe theg laName;
    char fiName[20];
    char laName[20];
    string recipName;
    char ch = 'Y'; 
    int intnum, total,hundthoucountthoucount;
	float amount;
	char strAmt, charAmt, teensandtens;
	
	char date;

	LoadCharAmt();

	do
    {
        cout << "\n\n************CHECK WRITER*************\n\n";

        cout << "Enter Last Name: ";
        cin.getline(laName, 20); // strings stored into arrays
        cout << "Enter Recipient First Name: ";
        cin.getline(fiName,20); 
        recipName = laName;
		recipName += " , ";
		recipName += fiName; 

        cout << "\n\n Enter the amount of the Check:(up to 99,999.99):999999.99 " << " $ " << endl;
        cin >> amountofCheck;
        
      			 
        cout << "\t Pay to the Order of: \t"<<  recipName << endl;
        cout << fixed << showpoint << setprecision(2) << endl; 
		cout << calculations(amountofCheck);// function
		
        cout << "\n\nDo you want to write another check? (Y/N):";
       
        cin >> ch; 

    } while(ch == 'Y' || ch == 'y');

    system("PAUSE"); 
	return 0;
}

void LoadCharAmt()
{

	charAmt[0] = "";
    charAmt[1] = "One";
    charAmt[2] = "Two";
    charAmt[3] = "Three";
    charAmt[4] = "Four";
    charAmt[5] = "Five";
    charAmt[6] = "Six";
    charAmt[7] = "Seven";
    charAmt[8] = "Eight";
    charAmt[9] = "Nine";
    charAmt[10] = "Ten";
    charAmt[11] = "Eleven";
    charAmt[12] = "Twelve";
    charAmt[13] = "Thirteen";
    charAmt[14] = "Fourteen";
    charAmt[15] = "Fifteen";
    charAmt[16] = "Sixteen";
    charAmt[17] = "Seventeen";
    charAmt[18] = "Eighteen"; 
    charAmt[19] = "Nineteen";
    charAmt[20] = "Twenty";
    charAmt[21] = "Ten";
    charAmt[22] = "Twenty";
    charAmt[23] = "Thirty";
    charAmt[24] = "Fourty";
    charAmt[25] = "Fifty";
    charAmt[26] = "Sixty";
    charAmt[27] = "Seventy";
    charAmt[28] = "Eighty";
    charAmt[29] = "Ninety";
}


string calculations(double amount)
{
    int tenthoucount = 0, thoucount = 0, hundcount=0, tencount = 0, numcount=0;
    string amtStr;
    int intnum;
    int intAmt = static_cast<int>(amount);
    
   if (intAmt <= 20000)
    {
		while (intAmt >= 1000)
		{
			intAmt -= 1000;
			thoucount++;
		}
		
		amtStr += charAmt[thoucount] + " Thousand ";
		
    }
    else
    {
    	while (intAmt > 10000)
    	{
    		intAmt -= 10000;
    		tenthoucount++;
    	}
    	amtStr += charAmt[tenthoucount + 20];

     }
    
     if (intAmt <= 10000)
	   {
	     while (intAmt >= 1000)
	   	{
	   		intAmt -= 1000;
     	    thoucount++;
	   	}
	   	amtStr += charAmt[thoucount] + " Thousand ";
       }
      
     while  (intAmt >= 100 )
	  {
          intAmt -= 100;
          hundcount++;
      }
        
      while (intAmt >= 10 )
      {
         intAmt -= 10;
     	 tencount++;
      }
     	
     while (intAmt >= 0 )
		{
     	  intAmt -= 0;
     	  numcount++;
     	}
     	
     	
    



		amount = amount - int(amount);
        intnum = static_cast<int>(( amount + 0.005) * 100);
        char charnum[10];
        itoa(intnum, charnum, 10);
        
		if(intnum > 0)
		{
			amtStr = amtStr + " Dollars and " + charnum + "/100";
		}           
        else
        	amtStr = amtStr + " Dollars and " + "00/100";
    
    return amtStr;
}
To start with, you don't need the function 'LoadCharAmt()' you can fill it in at the point of declaration thus:

1
2
3
//Global array
string charAmt[] = {"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen", 
							"Sixteen","Seventeen","Eighteen","Nineteen","Twenty","Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};

Why don't you explain in plain english what you are attempting to do. The 'calculations' function is riddled with errors, for example you are most likley to attempt to read a value from your 'charAmnt' array that is outside of the boundary, i.e. the index you use is too large!
Alright my main issue is that when I enter amount in the hundreds and lower it does not give me the accurate amount in words.
Last edited on
Topic archived. No new replies allowed.