Problem set Rewrite the following if statement as an equivalent switch statement. The variable digit is of...

80.2K

Verified Solution

Question

Programming

Problem set

  1. Rewrite the following if statement as an equivalent switchstatement. The variable digit is of type int.

if (digit == 0)

value = 3;

else if (digit == 1)

value = 3;

else if (digit == 2)

value = 6;

else if (digit == 3)

    value = 9;

  1. The decision table below shows fines imposed for speedingviolations. Write a code segment that assigns the correct fine totype double variable fine based on the value of type int variablespeed.

    Speed (mph) Fine ($)

    65 or less   0

   66-70        15.00

   71-75        30.00

   76-80        75.00

    over 80 100.00

  1. Rewrite the switch statement below as a multiple-alternative ifstatement.

    switch (jersey) {

    case 11:

         printf(\"I.Thomas\n\");

         break;

    case 23:

         printf(\"M.Jordan\n\");

         break;

    case 33:

         printf(\"S.Pippen\n\");

         break;

    default:

         printf(\"Playerunknown\n\");

    }

  1. What is the output of the following program?

         count = 5;

         while (count> 0) {

          print(“Woot! ”);

           count -=1;

         }

Answer & Explanation Solved by verified expert
4.3 Ratings (789 Votes)
Programincludeint main int digit2 Here initailizing the value of digit to 2if digit 0printfvalue 3else if digit 1printfvalue 3else if digit 2printfvalue 6else if digit 3printfvalue 9OutputUsing Equivalent switch statementProgramincludeint main int digit2 Here    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students