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. Only use and SWITCH statement.
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. Only use and SWITCH statement.
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...
Related questions
Question
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.
Only use <iostream> and SWITCH statement. Can you explain your code, please? Thank you so much

Transcribed Image Text:numberWords.cpp
numberWords.cpp
void write Tens(int tensDigit, int onesDigit)
switch(tensDigit)
case 1:
switch(onesDigit)
case 0:
cout<<"ten ";
break;
case 1:
if (hundreds!=0)
cout<<"hundred ";
cout<<"eleven ":
break;
}
break;
case 2:
cout<<"twenty ";
break;
case 3:
cout<<"thirty ";
break;
Once the program works for the example 123456789, try doing the teens by putting a
switch within a switch.
After that you can handle zeros or shorter numbers by using if statements to avoid printing
extra words.

Transcribed Image Text:numberWords.cpp
numberWords.cpp
numberWords.cpp
#include <iostream>
using namespace std;
void breakapart(int, int&, int&, int&);
void writeNum(int);
int main()
void writeNum(int threeDigits)
{
//break up number into single digits
Iwrite the hundreds digit
void writeSingle(int digit)
{
switch(digit)
case 1:
il break the number into three three-digit numbers
breakapart(num, first, second, third);
Ilwrite the first three-digit number
writeNum(first);
INrite "million"
Ilwrite "hundred"
Ilwrite the tens digit
Ilwrite the ones digit
}
cout<<"one ":
break;
case 2:
cout<<"two ";
break;
cout<<"million ";
Ilwrite the second three-digit number
writeNum(second);
INrite "thousand"
cout<<"thousand ";
Ilvrite the third three-digit number
writeNum(third);
INrite an endline
cout<<endl;
return 0;
To write a function that writes a digit in English, use a switch.
Breaking the number apart can be a function call. Writing a three-digit number can be
another function call. Writing "million" or "thousand" can be print statements.
To break a nine-digit number into three three-digit numbers, look at the commas video. To
write the name of a three digit number, break it into three one-digit numbers. Then write
the first digit. Write "hundred". Write the tens digit. Then write the ones digit.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Recommended textbooks for you

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY