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

Kyal is in line at the DMV he has number 325, they are currently serving custome

ID: 3877823 • Letter: K

Question

Kyal is in line at the DMV he has number 325, they are currently serving customer 320.

Use a switch statement to determine which type of loop he needs to use to count to his turn being called.
f = for loop w = while loop d = do-while loop
Output the appropriate loop type from the switch.

Then use any loop type to get from 320 to 325.

code:

#include <iostream>
using namespace std;

int main() {

// Declare appropriate variables
int number = 320;
  
//Output the prompt & recieve input
cout << "Select the apropriate loop type f= for, w =while, d= do-while" << endl;
  
//Switch to determine & output the appropriate loop type
  
  
//Loop that goes from 320 to 325 and outputs each number then "It's your turn"
  
  

return 0;
}

Explanation / Answer

//this program choose the loop to print the output based on the input from the user

#include <iostream>
#include <iomanip>

using namespace std;


int main() {
  
char ch;//for user information of loop
int number = 320;
  
//Output the prompt & receive input
cout << "Select the appropriate loop type f= for, w =while, d= do-while :" ;
cin>>ch;
  
//Switch to determine & output the appropriate loop type
switch(ch){
case 'W' ://if the user selects while loop
case 'w':
while(number <=325){
cout<<number++<<endl;
}
break;
case 'D'://if user selects the do loop
case 'd':
do{
cout<<number++<<endl;
}while(number<=325);
break;
case 'F'://if the user selects the for loop
case 'f':
for(; number<=325; number++){
cout<<number<<endl;
}
break;
default:
cout<<"Invalid Input.";
}
cout<<" it is your turn"; //display the message after printing the loop values
return 0;
}

output:

Select the appropriate loop type f= for, w =while, d= do-while :F
320
321
322
323
324
325

it is your turn
RUN SUCCESSFUL (total time: 2s)