Hello everyone. I have homework and I do but code is complicated for me.  Homework. This program reads a number of up to 9 digits. It then prints the number in English. In other words, if you run the program and enter 12345678, it should respond with "one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine". If you enter 10000, it ought to print "ten thousand". This program is intended to give you practice using the switch statement and variable parameters in functions. C++ Only use and SWITCH statement, not use array. Help me fix my code. I don't know how to handle it so that when I enter the number 1256789, it will output one million two hundred and fifty-six thousand seven hundred and eighty-nine. Can you help me? Thank you so muc

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello everyone. I have homework and I do but code is complicated for me. 

Homework.

This program reads a number of up to 9 digits. It then prints the number in English. In other words, if you run the program and enter 12345678, it should respond with "one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine". If you enter 10000, it ought to print "ten thousand". This program is intended to give you practice using the switch statement and variable parameters in functions.

C++ Only use <iostream> and SWITCH statement, not use array.

Help me fix my code. I don't know how to handle it so that when I enter the number 1256789, it will output one million two hundred and fifty-six thousand seven hundred and eighty-nine. Can you help me? Thank you so much

And this the picture my teacher require use in code

https://ibb.co/dQ4Mg27
https://ibb.co/xscJJsj
https://ibb.co/C8wT6Qp
https://ibb.co/rkQqGm6
https://ibb.co/kBCQZNz
https://ibb.co/Mn0cmtx

My code

#include <iostream>
using namespace std;


void breakapart(int n, int &a, int &b, int &c)
{
c*=c;
b*=b;
a*=a;
}

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

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<<"fouteen "; break;
case 5: cout<<"fiftenn "; 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<<"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<<"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/100;

one = n;
writeSingle(one);
cout<<"hundred";
writeTens(two, three);

}

int main()
{
int num, first, second, third;
cout<<"Input a 9 digit number ";
cin>>num;
// break the number into 3 parts
first = (num / 100000) % 100;
second = (num / 1000) % 100;
third = (num % 1000);

cout<<"first"<<first<<"\nsecond"<<second<<"\nthird"<<third<<endl;
//breakapart(num,first,second,third);
writeNum(first);
cout<<" million ";
writeNum(second);
cout<<" thousand ";
writeNum(third);
return 0;
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education