Hi all,
I've been instructed to write a program that inputs a dollar amount to be printed on a check, and then prints the amount in a check-protected format with leading asterisks of necessary. Nine spaces are available fore printing an amount (max of $99,999.99). The program looks like this:
#include <iostream>
using namespace std;
int main()
{
char amount[10];
int length = 0;
int i;
cout<< "Please enter the check amount: " << endl;
cin>> amount;
while(amount[length] != '\0')
{ length++;
}
for(i = 0; i < length; i ++)
{ amount[8-i] = amount[length-1-i];
}
for(i=0; i < 9-length; i++)
{ amount[i] = '*';
}
amount[9]='\0';
cout<<"The check amount is: " << amount << endl;
return 0;
}
This part of the code works great... my instructor wasn't clear on whether or not to include commas, I think I might have a little trouble with that part. Anyway, there's a second part to the problem, a continuation of sorts. Those requirements are to print out the amount in words on the second line. I have the code written up to the tens place. However, I'm not sure how to do the thousands and/or hundreds. Would anyone mind helping?? Here's the code I have so far for the second part
#include <iostream>
using namespace std;
int main()
{
char amount[10];
int length = 0;
int dollars = 0;
cout<< "Please enter the check amount: " << endl;
cin>> amount;
while((amount[length] != '.') && (amount[length] !='\0'))
{
dollars = (dollars * 10) + amount[length]-48;
length++;
}
if (dollars > 19)
switch(dollars/10)
{
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;
}
else if (dollars > 9)
{
switch(dollars)
{
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;
}
dollars = 0;
}
dollars = dollars % 10;
if ((dollars < 10) && (dollars > 0))
switch(dollars)
{
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;
}
dollars = 0;
while (amount[length] != '\0')
{
if(amount[length] != '.')
{
dollars = (dollars * 10 + amount[length]-48);
}
length++;
}
if(dollars > 0)
{
cout << " AND " << dollars << "/100" << endl;
}
return 0;
}
Thanks for your time,
iTsweetie