Help me fix my code. I have a problem my code when I input 112 output one hundred twelve two I want fix when I put 112 out one hundred twelve. Homework Write a program that reads a whole number of up...


Help me fix my code. I have a problem my code
when I input 112 output one hundred twelve two



I want fix when I put 112 out one hundred twelve.



Homework Write a program that reads a whole number of up to nine digits and prints it in words. For example, the input 13247 ought to produce "thirteen thousand two hundred forty seven"



Please use my code. Thank you so much


#include


using namespace std;


void breakapart(int n, int &a, int &b, int &c);
void writeNum(int digit);
void writeSingle(int n);
void writeTens(int tensD, int onesD);


int main()
{
int num, first, second, third;
cout<"input a="" 9="" digit="" number=""><>
cin>>num;
// Break the number into three three-digit numbers
breakapart(num,first,second,third);
writeNum(first);
// If number is above or equal to one million, print name million
if(num>=1000000)
{
cout<"million>
}
writeNum(second);


// If number second in break not equal to 0, print name thousand
if(second!=0)
{
cout<"thousand>
}
writeNum(third);
return 0;
}


//Break the number into three three-digit numbers
void breakapart(int n, int &a, int &b, int &c)
{

c = n%1000;
n = n/1000;


b = n%1000;
n = n/1000;


a = n%1000;
n = n/1000;
}


// Read number one digit
void writeSingle(int digit)
{
switch(digit)
{
case 1: cout<"one ";="">
case 2: cout<"two ";="">
case 3: cout<"three ";="">
case 4: cout<"four ";="">
case 5: cout<"five ";="">
case 6: cout<"six ";="">
case 7: cout<"seven ";="">
case 8: cout<"eight ";="">
case 9: cout<"nine ";="">
}
}


// Read number ten digit

void writeTens(int tensD, int onesD)
{
switch(tensD)
{
case 1:

switch(onesD)
{
case 0: cout<"ten ";="">
case 1: cout<"eleven ";="">
case 2: cout<"twelve ";="">
case 3: cout<"thirteen ";="">
case 4: cout<"fourteen ";="">
case 5: cout<"fifteen ";="">
case 6: cout<"sixteen ";="">
case 7: cout<"seventeen ";="">
case 8: cout<"eighteen ";="">
case 9: cout<"nineteen ";="">
}
break;
case 2: cout<"twenty ";="">
case 3: cout<"thirty ";="">
case 4: cout<"forty ";="">
case 5: cout<"fifty ";="">
case 6: cout<"sixty ";="">
case 7: cout<"seventy ";="">
case 8: cout<"eighty ";="">
case 9: cout<"ninty ";="">
}
}


void writeNum(int n)
{
// break number into single digit
int one, two, three;


three = n%10;
n = n/10;


two = n%10;
n = n/10;


one = n;


writeSingle(one);
// If number one above equal to 0, print name hundred
if(one > 0)
{
cout<"hundred>
}
writeTens(two, three);


writeSingle(three);
}


// break number into single digit<br>int one, two, three;<br>three - n$10;<br>n - n/10;<br>two - n$10;<br>n - n/10;<br>one - n;<br>writesingle (one);<br>// If number one above equal to 0, print name hundred<br>if (one > 0)<br>cout<<

Extracted text: // break number into single digit int one, two, three; three - n$10; n - n/10; two - n$10; n - n/10; one - n; writesingle (one); // If number one above equal to 0, print name hundred if (one > 0) cout<"hundred "; writetens (two, three); writesingle (three); not if n is in the teens. ";="" writetens="" (two,="" three);="" writesingle="" (three);="" not="" if="" n="" is="" in="" the="">
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here