LAB 4.4 - Working with if/else if Statements Step 1: Add the color.cpp program in your...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
LAB 4.4 - Working with if/else if Statements Step 1: Add the color.cpp program in your Lab4 folder to the project. Here is a copy of the source code. 1 // Lab 4 color.cpp 2 // This program lets the user select a primary color from a menu. 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 #include <string> 6 using namespace std; 7 8 int main() 9 { 10 int choice; should be 1, 2, or 3 11 12 13 // Display the menu of choices cout << "Choose a primary color by entering its number. \n\n"; 14 << "3 Yellow \n"; 15 16 17 18 19 picked 20 21 22 23 24 25 cout << "1 Red \n" << "2 Blue \n" 26 27 28 } // Menu choice // Get the user's choice cin >> choice; // Tell the user what he or she if (choice == 1) cout << "\nYou picked red.\n"; else if (choice == 2) cout << "\nYou picked blue.\n"; else yellow. \n"; cout << "\nYou picked return 0; Step 2: Compile the program and then run it 5 times. For each run enter the menu choice shown in the table below and write down the current output the program displays. Run output 1 2 3 4 5 Menu choice 1 2 3 0 99 New output Current Step 3: Improve the program so that only 1, 2, and 3 are accepted as valid choices. Make line 24 check for a choice of 3 before printing the message on line 25. Then add a trailing else that prints a descriptive error message whenever anything other than 1, 2, or 3 is entered. Step 4: Recompile the program and run it 5 more times, using the same 5 menu choices shown above. For each run, write wn the new output the program now displays. LAB 4.4 - Working with if/else if Statements Step 1: Add the color.cpp program in your Lab4 folder to the project. Here is a copy of the source code. 1 // Lab 4 color.cpp 2 // This program lets the user select a primary color from a menu. 3 // PUT YOUR NAME HERE. 4 #include <iostream> 5 #include <string> 6 using namespace std; 7 8 int main() 9 { 10 int choice; should be 1, 2, or 3 11 12 13 // Display the menu of choices cout << "Choose a primary color by entering its number. \n\n"; 14 << "3 Yellow \n"; 15 16 17 18 19 picked 20 21 22 23 24 25 cout << "1 Red \n" << "2 Blue \n" 26 27 28 } // Menu choice // Get the user's choice cin >> choice; // Tell the user what he or she if (choice == 1) cout << "\nYou picked red.\n"; else if (choice == 2) cout << "\nYou picked blue.\n"; else yellow. \n"; cout << "\nYou picked return 0; Step 2: Compile the program and then run it 5 times. For each run enter the menu choice shown in the table below and write down the current output the program displays. Run output 1 2 3 4 5 Menu choice 1 2 3 0 99 New output Current Step 3: Improve the program so that only 1, 2, and 3 are accepted as valid choices. Make line 24 check for a choice of 3 before printing the message on line 25. Then add a trailing else that prints a descriptive error message whenever anything other than 1, 2, or 3 is entered. Step 4: Recompile the program and run it 5 more times, using the same 5 menu choices shown above. For each run, write wn the new output the program now displays.
Expert Answer:
Answer rating: 100% (QA)
Step 1 This program lets the user select a primary color from a menu include include using namespace ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
I NEED HELP COMING UP WITH OPEN ENDED QUESTIONS MY RESEARCH ON POSITIVE PSYCHOLOGY As a Qualitative researcher who will be conducting interviews on your topic, write out some open-ended questions...
-
Why due diligence, both legal and financial, is important for the song catalog purchase? Why it is important to understand the details of sources of income, how and when it is earned, and how it is...
-
A researcher wanted to find out if there was difference between older movie goers and younger movie goers with respect to their estimates of a successful actors income. The researcher first...
-
Evaluate the limit of the sequence or state that it does not exist. an || u8 n!
-
A material having an index of refraction n is surrounded by a vacuum and is in the shape of a quarter circle of radius R (Fig. P35.66). A light ray parallel to the base of the material is incident...
-
Discuss how you can determine which of the following compounds might be alkanes, cycloalkanes, alkenes, or alkynes, without drawing their formulas: (a) C6H12. (b) C4H6. (c) C5H12. (d) C7H14, (e) C3H4.
-
The table at the left shows the sample ages of students in a class. Find the mean, median, and mode of the ages. Are there any outliers? Which measure of central tendency best describes a typical...
-
Two items are omitted from each of the following summaries of balance sheet and income statement data for two proprietorships for the year 2010, Craig Cantrel and Mills Enterprises....
-
A company is considering two mutually exclusive projects. The projected cash flows are as follows: Cash Flows:A Cash Flows:B Year 0 -$245,000 -$250,000 1 $70,500 $60,000 2 $85,000 $60,000 3 $90,000...
-
Hong Kong Island features steep, hilly terrain, as well as hot and humid weather. Travelling up and down the slopes therefore causes problems; this has led the city authorities to imagine rather...
-
Lisaza & Partner has been appointed as the companys auditor for Odit Berhad. She is considering the audit work to be performed in the accounts payable area for the current-year engagement. The...
-
McCauley Bagpipes produces two models: Model 24 has sales of 500 units with a contribution margin of $40 each; Model 26 has sales of 350 units with a contribution margin of $50 each. If sales of...
-
Calculate the duration using a five-year bond selling for $1,084.25, paying interest annually, with a face value of $1,000, an annual coupon rate of 8%, and a yield to maturity (YTM) of 6% Yield to...
-
How do historical precedents of communal living, such as intentional communities and cooperative movements, inform our understanding of current communal endeavors and aspirations for alternative...
-
Which worksheet consolidating entry will be made on December 31,20X9, if XYZ Corporation had initially purchased the land for$50,000 and then sold it to ABC on July 15, 20X8, for $70,000?
-
What role do respiratory pigments such as hemoglobin and myoglobin play in facilitating oxygen delivery and storage within the circulatory and muscular systems, and how do allosteric regulators...
-
ABC Inc. processes 5,650 cheques per month. Of these, 70% are for $60 and 30% are for $85. The $60 cheques are delayed two days, on average; the $85 cheques are delayed three days, on average. How...
-
Use the following data to answer the next two (2) questions: Product 1 Product 2 Product 3 Direct Material Cost $25,000 $30,000 $35,000 Direct Labor Cost $30,000 $40,000 $50,000 Direct Labor Hours...
-
Sophie is a single taxpayer. For the first payroll period in October 2012, she is paid wages of $3,250 monthly. Sophie claims three allowances on her Form W-4. a. Use the percentage method to...
-
Bill and Guilda each own 50 percent of the stock of Radiata Corporation, an S corporation. Guilda's basis in her stock is $25,000. On July 31, 2012, Bill sells his stock, with a basis of $40,000, to...
-
In 2012, Michael has net short-term capital losses of $2,000, a net long-term capital loss of $45,000, and other ordinary taxable income of $45,000. a. Calculate the amount of Michael's deduction for...
-
The MINITAB commands will create a normal scores plot from observations that were set in C1. (MINITAB uses a variant of the normal scores, \(m_{i}\), that we defined.) Construct a normal scores plot...
-
With reference to the preceding exercise, find the corresponding distribution function and use it to determine the probabilities that a random variable having this distribution function will take on...
-
Use the computing formula for \(\sigma^{2}\) to rework part (b) of the preceding exercise. Data From Preceding Exercise Determining a joint cumulative distribution function Find the joint cumulative...
Study smarter with the SolutionInn App