This program prints out a check. We had to write a function for digits 5,4,3 and a function for cents. I'm having trouble in two areas of the program. One is my teens are not printing out right, like instead of twelve I get ten two ect.
I've tried alot of different things but nothing has worked so far. Its probably something simple, but I just can't see it. The other problem is printing the amount out on the check, etc. $600.00, it prints the cents sometimes and sometimes not, depending upon the amount you entered if it has cents or not. If anyone has any suggestions, I would deeply appreicate it.
Here is the code:#include <iostream.h>
#include <iomanip.h>
#include <math.h>
//Check writing program, Final Test, CIS
//This program will write out the amount and pay to, date of a check when the amount is entered
//Date:12/13/01
void cents(int,int);
void WriteD3 (int);
void WriteD4 (int);
void WriteD5 (int);
int main()
{
int xamt=0,d1=0,d2=0,d3=0,d4=0,d5=0;
float amt;
cout << " Input the check amount and press enter: ";
cin >> amt;
cout << "_________________________________________________ ______________________________\n\n\n"<<endl;
cout << setw(45) << __DATE__ << endl;
cout << (" ") << endl;
cout << " WalMart " << " "<< " $ "<< amt << " " << endl; //THERE IS SOMETHING WRONG HERE WITH PRINTING OUT THE AMOUNT
//LIKE $600.00, THE OLD LINE WON'T PRINT ANYTHING. STILL WORKING ON
//THE TEEN PROBLEM!
cout << " " << endl;
cout << endl;
if (amt <= 1000.00)
{
xamt=amt * 100;
d1=xamt%10;
d2=xamt%100/10;
d3=xamt%1000/100;
d4=xamt%10000/1000;
d5=xamt%100000/10000;
}
WriteD5 (d5);
WriteD4 (d4);
WriteD3 (d3);
cents(d1,d2);
return 0;
}
void cents(int d1, int d2)
{
cout << " Dollars and ****************** " << " " << d2 << d1 << " /100 " << endl;
cout << "\n\n\n" << endl;
return ;
}
void WriteD5(int d5)
{
switch(d5)
{case 1:
cout <<" One Hundred ";
break;
case 2:
cout << " Two Hundred ";
break;
case 3:
cout << " Three Hundred ";
break;
case 4:
cout << " Four Hundred ";
break;
case 5:
cout << " Five Hundred ";
break;
case 6:
cout << " Six Hundred ";
break;
case 7:
cout << " Seven Hundred ";
break;
case 8:
cout << " Eight Hundred ";
break;
case 9:
break;
default: cout << " " ;
return ;
}
}
void WriteD4 (int d4)
{
int d3=0;
switch(d4)
{case 1:
if(d3==0)
cout<<"ten ";
else if(d3==1)
cout<<"eleven ";
else if(d3==2)
cout<<"twelve ";
else if(d3==3)
cout<<"thirteen ";
else if(d3==4)
cout<<"fourteen ";
else if(d3==5)
cout<<"fifteen ";
else if(d3==6)
cout<<"sixteen ";
else if(d3==7)
cout<<"seventeen ";
else if(d3==8)
cout<<"eighteen ";
else if(d3==9)
cout<<"nineteen ";
break;
case 2:
cout<<"Twenty-";
break;
case 3:
cout<<"Thirty-";
break;
case 4:
cout<<"Forty-";
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;
default:;
return ;
}
}
void WriteD3 (int d3)
{
int d4=0;
switch(d3)
{
case 1:
if(d4 !=1)
cout<<"one ";
break;
case 2:
if(d4!=1)
cout<<"Two ";
break;
case 3:
if(d3!=1)
cout<<"Three ";
break;
case 4:
if(d4 !=1)
cout<<"Four ";
break;
case 5:
if(d4 !=1)
cout<<"Five ";
break;
case 6:
if(d4 !=1)
cout<<"Six ";
break;
case 7:
if(d4 !=1)
cout<<"Seven ";
break;
case 8:
if(d4 !=1)
cout<<"Eight";
break;
case 9:
if(d4 !=1)
cout<<"Nine ";
break;
default:
cout<<" ";
return;
}
}