Created
March 4, 2015 21:44
-
-
Save anonymous/65c052277c67f03de643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Included Header Files | |
#include <iostream> | |
#include <iomanip> | |
#include <cstring> | |
#include <cstdlib> | |
#include <string> | |
#include <cstdio> | |
#include <math.h> | |
//Using the Standard Namespace | |
using namespace std; | |
//Constant Integer Sizes for Arrays | |
const int SIZE = 21; | |
const int LENGTH = 10; | |
//Numbers in the string format for lookup tables | |
const char lookUp[SIZE][LENGTH] = {"zero", "one", "two", "three","four","five","six","seven", | |
"eight","nine", "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen", | |
"eighteen","nineteen"}; | |
const char tens[SIZE-11][LENGTH-2] = {"\0", "ten", "twenty", "thirty","forty","fifty","sixty","seventy","eighty","ninety"}; | |
//Function Prototypes | |
void askForInformation (char date[], char name[], char amount[]); | |
void convertNumbersToWords(char amount[], char amountInWords[], char cents_str[], int & cents); | |
void printCheck (char date[], char name[], char amount[], char amountInWords[], char cents_str[], int & cents); | |
int main (void) | |
{ | |
//Declaring Variables | |
char date[9] = {"\0"}; | |
char name[20] = {"\0"}; | |
char amount[10] = {"\0"}; | |
char amountInWords[50] = {"\0"}; | |
char cents_str[] = ""; | |
int cents; | |
//Function Calls | |
askForInformation(date,name,amount); | |
convertNumbersToWords(amount, amountInWords,cents_str, cents); | |
printCheck(date, name, amount, amountInWords, cents_str, cents); | |
return 0; | |
} | |
//This function will ask the user for needed information for the program to function | |
void askForInformation (char date[], char name[], char amount[]) | |
{ | |
cout << "Please Enter A Date (MM/DD/YY): "; | |
cin.getline (date, 9); | |
cout << "Please Enter Payment Name: "; | |
cin.getline(name, 20); | |
//Validate amount because you can't send a check for anything less than or equal $0.00 or anything greater than 10,000.00 | |
do{ | |
cout << "Please Enter Payment Amount (DDDDD.CC): "; | |
cin.getline(amount, 9); | |
if (atof(amount) > 10000.00 || atof(amount) <= 0.00) | |
{ | |
cout << "Please enter an amount between 0 and 10,000." << endl; | |
} | |
}while(atof(amount) > 10000.00 || atof(amount) <= 0.00); | |
return; | |
} | |
//This function will use the look up tables to convert the amount from the user to words | |
void convertNumbersToWords(char amount[], char amountInWords[], char cents_str[], int & cents) | |
{ | |
//Declare Variables | |
double dollarAmount; | |
double temp; | |
int digit; | |
//Convert the string amount from the user to a double for math | |
dollarAmount = atof(amount); | |
//If the amount is 10,000.00 | |
if (static_cast<int>(dollarAmount) == 10000) | |
{ | |
strcat(amountInWords,"Ten thousand dollars and 0 cents"); | |
} | |
//If the amount falls in between 10,000.00 and 1000.00 | |
if (dollarAmount < 10000.00 && dollarAmount >= 1000.00) | |
{ | |
cents = (dollarAmount - static_cast<int>(dollarAmount)) * 100; | |
digit = (((static_cast<int>(dollarAmount)/ 1000))); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " thousand "); | |
dollarAmount -= (static_cast<double> (digit * 1000)); | |
digit = (((static_cast<int>(dollarAmount))/100)); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " hundred "); | |
dollarAmount -= (static_cast<double> (digit * 100)); | |
digit = (((static_cast<int>(dollarAmount)/ 10))); | |
strcat(amountInWords, tens[digit]); | |
dollarAmount-=(static_cast<double>(digit * 10)); | |
digit = (((static_cast<int>(dollarAmount)/ 1))); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " dollars and "); | |
} | |
//If the amount falls between 1000.00 and 100.00 | |
if (dollarAmount < 1000.00 && dollarAmount >= 100.00) | |
{ | |
cents = (dollarAmount - static_cast<int>(dollarAmount)) * 100; | |
digit = (((static_cast<int>(dollarAmount))/100)); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " hundred "); | |
dollarAmount -= (static_cast<double> (digit * 100)); | |
digit = (((static_cast<int>(dollarAmount)/ 10))); | |
strcat(amountInWords, tens[digit]); | |
dollarAmount-=(static_cast<double>(digit * 10)); | |
digit = (((static_cast<int>(dollarAmount)/ 1))); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " dollars and "); | |
} | |
//If the amount falls between 100.00 and 10.00 | |
if (dollarAmount < 100.00 && dollarAmount >= 10.00) | |
{ | |
cents = (dollarAmount - static_cast<int>(dollarAmount)) * 100; | |
digit = (((static_cast<int>(dollarAmount)/ 10))); | |
strcat(amountInWords, tens[digit]); | |
dollarAmount-=(static_cast<double>(digit * 10)); | |
digit = (((static_cast<int>(dollarAmount)/ 1))); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " dollars and "); | |
} | |
//IF the amount falls between 10.00 and 1.00 | |
if (dollarAmount < 10.00 && dollarAmount >= 1.00) | |
{ | |
cents = (dollarAmount - static_cast<int>(dollarAmount)) * 100; | |
digit = (((static_cast<int>(dollarAmount)/ 1))); | |
strcat(amountInWords, lookUp[digit]); | |
strcat(amountInWords, " dollars and "); | |
} | |
//If the amount falls between 1.00 and 0.00 | |
if (dollarAmount < 1.00 && dollarAmount > 0.00) | |
{ | |
cents = (dollarAmount * 100.00); | |
} | |
return; | |
} | |
//This function will print out the simulated check to the screen for the user to read | |
void printCheck (char date[], char name[], char amount[], char amountInWords[], char cents_str[], int & cents) | |
{ | |
cout << setw(50) << right << "Date: " << date << endl << endl; | |
cout << left << "Pay the order of: " << name << right << setw(20) << "$" << amount << endl << endl; | |
cout << amountInWords << cents << "cents"; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment