Skip to main content

rock paper scissors game

rock paper scissors game

#include <iostream> //you have to include this in every c++ file
#include <stdlib.h> //for rand() and new
#include <vector>   //for arrays
#include <stdio.h>  //for printf()

using namespace std ; //you have to include this in every c++ file as well


//////////////////////////////////////////////main function////////////////////////////////////////////////////

int main() //you have to include this in every c++ file too
          {
        //these are the choices
    char * x[] = {"rock", "paper", "scissors"};
   

    //strings are big, so ill allocate memory
   
    string * a = new string(
"FUCK"
); // fuck is only a placeholder until it gets replaces
   
   
  

    //this for loop will go on until a is equal to something else
    for (
;
*a != "rock" // != means "not", so this code basically says, "while *a is not equal to "rock""
and
 *a != "scissors"
and
 *a != "paper";) //code formatted like this is easier for me to read :)
                                                            {
        //this means a will be written to by standard input
        cin >> *a; //a is the string variable from before
      
    }
        //strings are big, so ill allocate memory
    string * c = new string(x[rand() % 3]);
        //c is the computers choice, and its random. thats why i used rand()   

    //if a == c, then this code will run
    if (
*a == *c
)
    {
        //this meaans that it will print "tie" to the console.
        cout<< "tie";
    }
   

    if (*a == "rock" && *c == "scissors" || *a == "paper" && *c == "rock" || *a == "scissors" && *c == "paper")// if any of this happens, then this code will happen.
                                                                                                              {
         cout<< "win";
    }
    else
          {
    cout << "lose";
   }

   return 0; //if main returns 0, that means that its good. if it doesnt, then you just gotta do a bunch of trial and error until it does.
}

////////////////////////////////////////////////////////////////////////////////////s///////////////////////////