01/10/2018, 08:15
Game Oẳn tù tì :p
Mình bị lỗi logic trong đoạn code này, mọi người xem hộ là lỗi gì nhé :D, Bí quá:
Đây là trò chơi Oẳn tù tì; qui ước: Búa = ‘b’; Bao = ‘o’: Kéo = ‘k’
Mình có cmt bên cạnh nhé
#include <iostream>
using namespace std;
char Player_1;
char Player_2;
int main()
{
cout << "(Play 1) press: ";
cin >> Player_1; // Character Player 1 (Pl1) press in (b, o ,k)
cout << endl;
cout << "(Play 2) press: ";
cin >> Player_2; // Character Player 2 (Pl2) press in (b, o ,k)
cout << endl;
//---------------------------------------------------------------------------------------------------
if(Player_1 = Player_2) // If both Char same, compile will put out the Line "EVEN - Game OVER"
{
cout << "EVEN _ GAMe OVER" << endl;
}
else if(Player_1 = 'o') //If Pl1 press 'o', Pl2 press 'k'
{
if(Player_2 = 'k')
{
cout << "Player 2 win, PLayer 1 lozz" << endl;
}
else if(Player_2 = 'b') //If Pl1 press 'o', Pl2 press 'b'
{
cout << "PLayer 1 win, PLayer 2 lozz"<< endl;
}
}
else if(Player_1 = 'k') //If Pl1 press 'k', Pl2 press 'o'
{
if(Player_2 = 'o')
{
cout << "Player 1 win, PLayer 2 lozz" << endl;
}
else if(Player_2 = 'b') //If Pl1 press 'k', Pl2 press 'b'
{
cout << "PLayer 2 win, PLayer 1 lozz"<< endl;
}
}
else if(Player_1 = 'b') //If Pl1 press 'b', Pl2 press 'o'
{
if(Player_2 = 'o')
{
cout << "Player 2 win, PLayer 1 lozz" << endl;
}
else if(Player_2 = 'k') //If Pl1 press 'b', Pl2 press 'o'
{
cout << "PLayer 1 win, PLayer 2 lozz"<< endl;
}
}
system("pause");
return 0;
}
Bài liên quan
Mấy câu
if
của bạn toàn là=
Thế mình phải ghi là == à ?
câu lệnh
if
dùng so sánh==
nha bạnCẢm ơn bạn rất nhiều :D, mình quên ko để ý
Giờ nó chạy ngon rồi : D thanks nhá
Toán tử so sánh là ==
Nhưng bạn sẽ thấy những câu viết ntn (!)