c practice problem Computers are frequently employed in chec

c++ practice problem.

Computers are frequently employed in check-writing systems such as payroll and accounts payable applications. Write a program that inputs a numeric check amount and writes the word equivalent of the amount. For example, the amount 221.23 should be written as: TWO HUNDRED TWENTY ONE and 2 3/100

Solution

#include using namespace std; int bufferNum = 0, Func[3] = {0, 0, 0}, part[3] = {0, 0, 0}, a, b, c, d; long num, numFake = 0; const char ones[][20] = {\"\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"}; const char tens[][20] = {\"\", \"ten\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"}; void convert(int temp); int main() { cout << \"Enter the number:\"; cin >> num; nFake = num; bufferNum = 0; while (numFake) { part[] = numFake % 1000; numFake /= 1000; bufferNum++; } if (bufferNum == 0) { cout << \"Zero.\"; } else if (bufferNum == 1) { convert(part[0]); } else if (bufferNum == 2) { convert(part[1]); cout << \" thousand,\"; convert(part[0]); } else { convert(part[2]); cout << \" million,\"; if (part[1]) { convert(part[1]); cout << \" thousand,\"; } else { cout << \"\"; } convert(part[0]); } } void convert(int temp){ bufferNum = 0; if (temp >= 100) { int a = temp / 100; int b = temp % 100; if (b) cout << \" \" << ones[a] << \" hundred and\"; else cout << \" \" << ones[a] << \" hundred \"; if (b < 20) cout << \" \" << ones[b]; else { int c = b / 10; cout << \" \" << tens[c]; int d = b % 10; cout << \" \" << ones[d]; } } else { b = temp; if (b < 20) cout << ones[b]; else { c = b / 10; cout << tens[c]; d = b % 10; cout << \" \" << ones[d]; } } }
c++ practice problem. Computers are frequently employed in check-writing systems such as payroll and accounts payable applications. Write a program that inputs

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site