jurusan :rpl cara membetulkan gimana ini udah??..#include <iostream>#include <stdio.h>#include <time.h>#include

Berikut ini adalah pertanyaan dari dewiSurya1111 pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas

Jurusan :rpl cara membetulkan gimana ini udah??..#include <iostream>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <windows.h>

using namespace std;
int main()
{
system("color 5e");
// Pilihan Player
int lagi, pilih;
a:cout << "===================================" << endl;
cout << " Selamat datang di GAME SUWIT JAWA " << endl;
cout << "===================================" << endl << endl;
cout << " Kamu Pilih ?" << "\n\n";
cout << " 1. GAJAH, \n 2. SEMUT, \n 3. ORANG" << "\n";
cout << " Silahkan Pilih 1/2/3 : => ";
cin >> pilih;
if(pilih==1)
{
cout << "\n Kamu = GAJAH" << endl;
srand(time(NULL)); // bilangan random/acak
int com = rand() % 10;
if (com<=3 && com>=1)
{
cout << " Computer = GAJAH" << "\n\n";
cout << " ==============" << endl;
cout << " ==> SERI ! <==" << endl;
cout << " ==============" << endl;
}
else if (com<=6 && com>=4)
{
cout << " Computer = ORANG" << "\n\n";
cout << " =====================" << endl;
cout << " ==> Kamu Menang ! <==" << endl;
cout << " =====================" << endl;
}
else
{
cout << " Computer = SEMUT" << "\n\n";
cout << " ====================" << endl;
cout << " ==> Kamu Kalah ! <==" << endl;
cout << " ====================" << endl;
} cout << endl;
}
else if(pilih==2)
{
cout << "\n Kamu = SEMUT" << endl;
srand(time(NULL)); // bilangan random/acak
int com = rand() % 10;
if (com<=3 && com>=1)
{
cout << " Computer = SEMUT" << "\n\n";
cout << " ==============" << endl;
cout << " ==> SERI ! <==" << endl;
cout << " ==============" << endl;
}
else if (com<=6 && com>=4)
{
cout << " Computer = GAJAH" << "\n\n";
cout << " =====================" << endl;
cout << " ==> Kamu Menang ! <==" << endl;
cout << " =====================" << endl;
}
else
{
cout << " Computer = ORANG" << "\n\n";
cout << " ====================" << endl;
cout << " ==> Kamu Kalah ! <==" << endl;
cout << " ====================" << endl;
} cout << endl;
}
else if(pilih==3)
{
cout << "\n Kamu = ORANG" << endl;
srand(time(NULL)); // bilangan random/acak
int com = rand() % 10;
if (com<=3 && com>=1)
{
cout << " Computer = ORANG" << "\n\n";
cout << " ==============" << endl;
cout << " ==> SERI ! <==" << endl;
cout << " ==============" << endl;
}
else if (com<=6 && com>=4)
{
cout << " Computer = SEMUT" << "\n\n";
cout << " =====================" << endl;
cout << " ==> Kamu Menang ! <==" << endl;
cout << " =====================" << endl;
}
else
{
cout << " Computer = GAJAH" << "\n\n";
cout << " ====================" << endl;
cout << " ==> Kamu Kalah ! <==" << endl;
cout << " ====================" << endl;
} cout << endl;
}
else
{
cout << "yang anda input salah !!" << endl;
}

cout << "pilih lagi = [0] : ";
cin >> lagi;b:

if (lagi == 0)
{
system ("cls");
goto a;
}
}

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

Jawaban:

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main()

{

   int lagi, pilih;

   do

   {

       system("cls");

       cout << "===================================" << endl;

       cout << " Selamat datang di GAME SUWIT JAWA " << endl;

       cout << "===================================" << endl << endl;

       cout << " Kamu Pilih ?" << "\n\n";

       cout << " 1. GAJAH, \n 2. SEMUT, \n 3. ORANG" << "\n";

       cout << " Silahkan Pilih 1/2/3 : => ";

       cin >> pilih;

       if (pilih < 1 || pilih > 3)

       {

           cout << "Input yang anda masukkan salah" << endl;

           cout << "Silakan input ulang" << endl;

           continue;

       }

       srand(time(NULL));

       int com = rand() % 3 + 1;

       string player, computer;

       bool isDraw = false, isWin = false;

       switch (pilih)

       {

           case 1:

               player = "GAJAH";

               if (com == 1)

               {

                   computer = "GAJAH";

                   isDraw = true;

               }

               else if (com == 2)

               {

                   computer = "SEMIT";

                   isWin = true;

               }

               else

               {

                   computer = "ORANG";

                   isWin = false;

               }

               break;

           case 2:

               player = "SEMIT";

               if (com == 1)

               {

                   computer = "GAJAH";

                   isWin = false;

               }

               else if (com == 2)

               {

                   computer = "SEMIT";

                   isDraw = true;

               }

               else

               {

                   computer = "ORANG";

                   isWin = true;

               }

               break;

           case 3:

               player = "ORANG";

               if (com == 1)

               {

                   computer = "GAJAH";

                   isWin = true;

               }

               else if (com == 2)

               {

                   computer = "SEMIT";

                   isWin = false;

               }

               else

               {

                   computer = "ORANG";

                   isDraw = true;

               }

               break;

       }

       // Output hasil

       cout << endl << " Kamu = " << player << endl;

       cout << " Computer = " << computer << endl << endl;

       if (isDraw)

       {

           cout << " ==============" << endl;

           cout << " ==> SERI ! <==" << endl;

           cout << " ==============" << endl;

       }

       else if (isWin)

       {

           cout << " =====================" << endl;

           cout << " ==> Kamu Menang ! <==" << endl;

           cout << " =====================" << endl;

       }

       else

       {

           cout << " ====================" << endl;

           cout << " ==> Kamu Kalah ! <==" << endl;

           cout << " ====================" << endl;

       }

       cout << endl << "pilih lagi? [1=ya, 0=tidak] : ";

       cin >> lagi;

   } while (lagi != 0);

   return 0;

}

Penjelasan:

꧁༒αηѕωєяє∂ ву gσ∂кєу༒꧂

Semoga dengan pertanyaan yang sudah terjawab oleh ganang dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Mon, 22 May 23