C++ Switch Case

Contoh Program C++ Switch Case


source code :

#include <iostream>

using namespace std;

int main()
{
  int input;
  cout<<"1. Play game\n";
  cout<<"2. Load game\n";
  cout<<"3. Play multiplayer\n";
  cout<<"4. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  switch ( input ) { // pemilihan dari input
  case 1:
    cout << "Horay..! Playing Game!";
    break; // berhenti dari program
  case 2:
   cout << "Please Wait... Load Game!\n";
    break;
  case 3:
    cout << "Do you want play Multi player ?";
    break;
  case 4:
    cout<<"Thank you for playing!\n";
    break;
  default:
    cout<<"Error, bad input, quitting\n";
    break;
  }
    return 0;
}

Share:

0 komentar