Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

activity | 2.6.1: rock - paper - scissors. organize the lines of code t…

Question

activity | 2.6.1: rock - paper - scissors.
organize the lines of code to create a switch statement that checks nextchoice.
if the input is 0, then the output is: rock
if the input is 1, then the output is: paper
if the input is 2, then the output is: scissors
for any other input, the output is: unknown
how to use this tool
unused
case 0:
}
default:
cout << \unknown\ << endl;
case 1:
case 2:
cout << \scissors\ << endl;
break;
switch (nextchoice) {
cout <<
ock\ << endl;
break;
cout << \paper\ << endl;
break;
main.cpp
#include <iostream>
using namespace std;
int main() {
int nextchoice;
cin >> nextchoice;
return 0;
}

Explanation:

Step1: Insert switch statement

Add switch (nextChoice) { between cin >> nextChoice; and return 0;

Step2: Add case 0 block

Insert:

case 0:
    cout << "Rock" << endl;
    break;

inside the switch braces

Step3: Add case 1 block

Insert:

case 1:
    cout << "Paper" << endl;
    break;

after case 0 block

Step4: Add case 2 block

Insert:

case 2:
    cout << "Scissors" << endl;
    break;

after case 1 block

Step5: Add default block

Insert:

default:
    cout << "Unknown" << endl;

after case 2 block

Step6: Close switch statement

Add } after the default block

Answer:

The completed main.cpp code is:

#include <iostream>
using namespace std;

int main() {
    int nextChoice;

    cin >> nextChoice;

    switch (nextChoice) {
        case 0:
            cout << "Rock" << endl;
            break;
        case 1:
            cout << "Paper" << endl;
            break;
        case 2:
            cout << "Scissors" << endl;
            break;
        default:
            cout << "Unknown" << endl;
    }

    return 0;
}