Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

programming C++ Exercise 3.3.1. The program in Example 3.3 (the number-printing program) is more useful if it allows repeated use rather than requiring you to

programming C++

Exercise 3.3.1. The program in Example 3.3 (the number-printing program) is more useful if it allows repeated use rather than requiring you to restart it every time. (Actually thats true of most programs.) Therefore, place the bulk of the program in a do-while loop that repeats until the user enters 0, at which point it exits.

Exercise 3.3.2. Revise the program so that it can handle numbers in the range 0 to 9. This should be easy.

Exercise 3.3.3. Revise the program so that it can handle numbers in the range 11 to 19. This will require a good deal more work than Exercise 3.3.2 does, because you have to account for all the teen words.

Exercise 3.3.4. Extend the program so that it handles values as high as 999. (Hint: youll need to complete Exercise 3.3.3 first, or the range of acceptable values will have many holes in it.)image text in transcribed

and statement is itself a state defau labe example case case case case Case cout "Char. Is break Example 3.3, Print a Number Although computers simple num for presentation to humans. The most sophist erized phone which change numerical we're not going to do anything quite that ten equivalent: printing out numbers in a logic is the same as that used for phone natural and the following application istake print it out in English- example printing printnum.cpp include ciostre amo sing name space std; int mai no cout "Enter a number from 20 to n 10; int tens digits n N 10 fnt units digits The switch-case Statement switch(tens digits) t 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 switch (units digits) f case 1: cout "one" endi break case 2: cout "two" endl break case 3: cout three endl break case 4: cout "four" endl break. case 5: ut "five" endl break case 6: cout six endl; break. case 7: cout Seven endl break case 8: cout eight" endl break case 9: cout nine endl; break How It Works If you've programmed before in another computer language, you might object that this example could be made much more efficient with something called an "array." That's absolutely true, and I'll get to that efficiency improvement in Chapter 6. Arrays: All in a Row-- But assume for now that switch case is the best have. To understand how this program worksit's necessary to review the division and remainder operators. The division operator, when applied to two inte gers, produces an integer result, rounded down. So, for example, let's suppose the user enters the number 49. The first thing the program doesisextract the tens digit as follows: 49 /10 If the program were, instead, working with floating point data las in the expression 49 01 100), the answer would be 49, which, if becomes 50. But only integers are involved here so the result is rounded down to 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

Students also viewed these Databases questions