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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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 <iostream>

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 "<<endl;
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 "; 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;
}
}

// Read number ten digit
void writeTens(int tensD, int onesD)
{
switch(tensD)
{
case 1:
switch(onesD)
{
case 0: cout<<"ten "; break;
case 1: cout<<"eleven "; break;
case 2: cout<<"twelve "; break;
case 3: cout<<"thirteen "; break;
case 4: cout<<"fourteen "; break;
case 5: cout<<"fifteen "; break;
case 6: cout<<"sixteen "; break;
case 7: cout<<"seventeen "; break;
case 8: cout<<"eighteen "; break;
case 9: cout<<"nineteen "; break;
}
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<<"ninty "; break;
}
}

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
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.
Transcribed Image 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY