Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a switch-statement to calculate the cost of produce: 1 - grapes @ $1.9

ID: 3808299 • Letter: C

Question

Construct a switch-statement to calculate the cost of produce: 1 - grapes @ $1.99/lb. 2 - strawberries @ $ 1.50/lb. 3 - apples @ $0.99/lb. Use int produce and double pounds as your produce and weight variables. A while-loop is a ________-controlled loop A for-loop is a ________-controlled loop One execution of a loop block is called what? A while-loop that never evaluates to false is said to be in what? True or False: a for-loop executes a fixed number of times? Which type of loop -- for-loop or while loop -- is used when we don't know how many iterations are to be performed? For (i = 0: 2: 20) executes how many iterations?

Explanation / Answer

9.

#include <iostream>
using namespace std;

int main()
{
   int produce;
   double weight,cost;
   cout<<"Enter produce and weight";
   cin>>produce;
  
   cin>>weight;
   switch(produce)
   {
        case 1: cout<<"Grapes at @ $1.99/lb";
                cost = weight *1.99;
                break;
        case 2: cout<<"Strawberries at @ $1.5/lb";
                cost = weight *1.5;
                break;
        case 3: cout<<"Apples at @ $0.99/lb";
                cost = weight *0.99;
                break;
        default: cout<<"Invalid produce ";
                cost = 0;
                break;
   }
  
   cout<<" Cost = "<<cost;
   return 0;
}

10. A while loop is event controlled loop.

11. A for loop is count controlled loop.

12. iteration

13. infinite loop

14. true

15. while loop

16. 11 iterations (0,2,4,6,8,10,12,14,16,18,20)