Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume that the playgame, loadgame and playmultiplayer functions have all been previously defined in a header file called game.h (not provided here). Consider the following
Assume that the playgame, loadgame and playmultiplayer functions have all been previously defined in a header file called game.h (not provided here). Consider the following function in a file that has a #include "game.h" and #include
void switchFunction(int input) { switch ( input ) { case 1: // Note the colon, not a semicolon playgame(); break; case 2: // Note the colon, not a semicolon loadgame(); break; case 3: // Note the colon, not a semicolon playmultiplayer(); break; case 4: // Note the colon, not a semicolon std::cout<<"Thank you for playing! "; break; default: // Note the colon, not a semicolon std::cout<<"Error, bad input, quitting "; break; } }
Which of the following function accomplishes the same result?
void getFunction(int input) { if(input == 1) playgame(); if(input==2) loadgame(); if(input==3) playmultiplayer(); if(input==4) std::cout<<"Thank you for playing! "; else std::cout<<"Error, bad input, quitting "; } |
void getFunction(int input) { if(input == 1) playgame(); else if(input==2) loadgame(); else if(input==3) playmultiplayer(); else if(input==4) std::cout<<"Thank you for playing! "; else std::cout<<"Error, bad input, quitting "; } |
void getFunction(int input) { if(input == 1 || input == 2) loadgame(); playgame(); else if(input==3) loadgame(); playmultiplayer(); else if(input==4) std::cout<<"Thank you for playing! "; else std::cout<<"Error, bad input, quitting "; } |
void getFunction(int input) { if(input == 1) playgame(); else if(input==2) loadgame(); else if(input==3) playmultiplayer(); else if(input==4) cout<<"Thank you for playing! "; else if(input > 4) cout<<"Error, bad input, quitting "; } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started