I am trying figure out how to generate random choices by the computer. I think I know what I'm doing in theory but I need someone to point me in the right direction as far as coding. I know the random number generator works, so I want to set it up so that if the random number is 0 then computerChoice is going to be equal to word "Paper", if the number is 1, then computerChoice is equal to "Rock"..and so on and so forth. I didn't think it would work to just set the variable equal to the word, I gave it a try and sure enough it didn't work. Could someone tell me how I can make computerChoice equal to a certain word?
Code:#include <stdlib.h>
#include <time.h>
#include <iostream.h>
int main()
{
char computerChoice[10]=""
srand((unsigned)time(NULL)); //Casts time's return to unsigned
int d=rand()%3; //Should be more random now
if(d==0)
{
cout<<"Computer choice: Paper"<<endl;
computerChoice="Paper";
}
if(d==1)cout<<"Computer choice: Rock"<<endl;
if(d==2)cout<<"Computer choice: Scissors"<<endl;
cout<<d;
return 0;
}