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

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

My 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++ just only use <iostream> and SWITCH statement. Thank you so much

And my this code, help me fix it.

#include <iostream>

using namespace std;

//Read number one digit
void one(int x)
{
switch(x){
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 digit2(int x)
{
switch(x)
{
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;
}
}

//Read ten number
void ten(int x)
{
switch(x){
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<<"ninety";
break;
}
}

//Read number hundred
void hundred(int x)
{
one(x);
cout<<" hundred";
}

//Read a thousand number
void thousand(int x)
{
one(x);
cout<<" thousand";
}

//Read a ten thousand number
void tensthousand(int x)
{
ten(x);
cout<<" thousand";
}

//Read a number tens of thousands
void tenshundredthousands(int x)
{
one(x);
cout<<" hundred thousand";
}

//Read a number million
void million(int x)
{
one(x);
cout<<" million";
}

//Read a number ten million
void tenmillion(int x)
{
ten(x);
cout<<" million";
}

//Read a number hundred million
void hundredmillion(int x)
{
one(x);
cout<<" hundred million";
}

int main()
{
int n;
char a, b, c, d, e, f, g, h, t, j;
cout<<"Input a 9 digit positive: ";
cin>>n;

//Separate numbers in millions, hundreds of thousands, tens of thousands, thousands, hundreds, tens, and units
a = n%10;
b = (n/10)%10;
c = (n/100)%10;
d = (n/1000)%10;
e = (n/10000)%10;
f = (n/100000)%10;
g = (n/1000000)%10;
h = (n/10000000)%10;
t = (n/100000000)%10;

// Read the numbers just split above
if(n<10)
{
one(a);
cout<<a<<endl;
}
else if(n>=10 && n<100)
{
ten(b);
cout<<b<<endl;
}
else if(n>=100 && n<1000)
{
hundred(c);
cout<<c<<endl;
}
else if(n>=1000 && n<10000)
{
thousand(d);
cout<<d<<endl;
}
else if(n>=10000 && n<100000)
{
tensthousand(f);
cout<<f<<endl;
}
else if(n>=100000 && n<1000000)
{
tenshundredthousands(g);
cout<<g<<endl;
}
else if(n>=1000000 && n<10000000)
{
million(h);
cout<<h<<endl;
}
else if(n>=10000000 && n<100000000)
{
tenmillion(f);
cout<<f<<endl;
}
else
{
hundredmillion(t);
cout<<t<<endl;
}
return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE 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