Advertisement
botvn

KeoBaoBua

Mar 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include<iostream>
  2. #include<Windows.h>
  3. #include<time.h>
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8.     int AI, player;
  9.  
  10.     //random ngau nhien 1 so tu 0 toi 2
  11.     srand(time(NULL));
  12.     AI = rand() % 3;
  13.  
  14.     cout << "0: Bua\n";
  15.     cout << "1: Keo\n";
  16.     cout << "2: Bao\n";
  17.     cout << "Nhap dap an ban muon chon: ";
  18.     cin >> player;
  19.  
  20.  
  21.     //xuat ket qua may chon
  22.     switch (AI)
  23.     {
  24.     case 0:cout << "May ra Bua"; break;
  25.     case 1:cout << "May ra Keo"; break;
  26.     case 2:cout << "May ra Bao"; break;
  27.     }
  28.     cout << endl;
  29.  
  30.     //xuat ket qua nguoi choi chon
  31.     switch (player)
  32.     {
  33.     case 0:cout << "Ban ra Bua"; break;
  34.     case 1:cout << "Ban ra Keo"; break;
  35.     case 2:cout << "Ban ra Bao"; break;
  36.     }
  37.     cout << endl;
  38.     //tinh toan nguoi hay may win
  39.     if (player == AI)
  40.         cout << "Hoa nhau";
  41.     else if ((player == 0 && AI == 1) || (player == 1 && AI == 2) || (player == 2 && AI == 0))
  42.         cout << "Ban thang";
  43.     else
  44.         cout << "May Thang";
  45.  
  46.     cout << endl;
  47.     system("pause");
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement