Question #99422

Write a switch statement that checks nextChoice. If 0, print "Rock". If 1, print "Paper". If 2, print "Scissors". For any other value, print "Unknown". End with newline.
#include <iostream>
using namespace std;

int main() {
int nextChoice;

cin >> nextChoice;

/* Your solution goes here */

return 0;
}

Expert's answer

// Write a switch statement that checks nextChoice.
// If 0, print "Rock". If 1, print "Paper".
// If 2, print "Scissors". For any other value, print "Unknown". End with newline.
#include <iostream>
using namespace std;
int main() {
    int nextChoice;
    cin >> nextChoice;
    /* Your solution goes here */
    switch(nextChoice){
        case 0: cout<<"Rock"; break;
        case 1: cout<<"Paper"; break;
        case 2: cout<<"Scissors"; break;
        default: cout<<"Unknown"; break;
    }
    cout<<endl;
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS