Im trying to familiarize myself with the string thing, char, comparing strings, ect. by writing a program that allows a user to play rock paper scissors against a computer who obviously is going to choose randomly...so my original goal was to code this game in the fewest lines of code possible and use the string compare to compare the computer and user choices and decide who wins, and then little things like play 3 rounds and allow the user to play again if he wants, but I can pretty much take care of that. However, as with most projects, I figured out the beginning and just when i get to the most important part I get stuck.
This is what I've gotten so far
Code:#include <iostream> #include <stdlib.h> #include <string.h> #include <cstdlib> using namespace std; void main() { //initialize variables for intro screen char yesOrno[10] = ""; int checkLoop = 0; char roundnum[10]=""; int validChoice=0; char playerPut[10]= ""; int computerPut=0; //while loop is set to different values to identify whether to repeat the intro screen again or not while(checkLoop == 0){ //intro screen - ***** Just ignore all the cout stuff below this, I had it all set up and lined up to show the directions but when I pasted the code under here it messed up the spacing. cout << " " << endl; cout << " Rock Paper Scissors " << endl; cout << " __________________________________________________________________________ " << endl; cout << "| This is a game of rock, paper, scissors. You will play three rounds | " << endl; cout << "| against the computer. To pick either rock, paper, or scissors simply | " << endl; cout << "| type in your choice and hit enter. The computer will randomly pick its | " << endl; cout << "| choice. At the end of the game type y to play again & n to end the game.| " << endl; cout << "| Do you understand? please enter y or n | " << endl; cout << "|__________________________________________________________________________| " << endl; //The end of that messy screen //user input cin.getline(yesOrno, 10); if((strcmp(yesOrno,"n")==0)||(strcmp(yesOrno,"y")==0)) //if the user input is a y or n go into this other loop { if(strcmp(yesOrno,"y")==0) { checkLoop=1; system("CLS"); cout<< "Get ready to start the game"<<endl; } else //if the user input is no repeat the directions { system("CLS"); cout<< "Read the directions again"; checkLoop=0; //makes this loop repeat until y or n entered } } else { system("CLS"); cout<< " Enter a y or n "<<endl; //if the user enters something other than a y or n print this statement cout<<endl; cout<<endl; }} system("CLS"); cout<<"Enter your choice"<<endl; cin.getline(playerPut,20); system("CLS"); while(validChoice==0) { if((strcmp(playerPut,"paper")==0)||(strcmp(playerPut,"rock")==0)||(strcmp(playerPut,"scissors")==0)) { validChoice=1; cout<< "Your choice was:"<<endl; cout<< playerPut<< endl; computerPut=rand()4%; //and this right here is pretty much where I got stuck, but i attempted to slowly drudge on if(strcmp(playerPut,"paper")==3) cout<< "works"<< endl; } } else { system("CLS"); cout<<"Not a valid choice."<< endl; validChoice=0; } } }
Any suggestions that would help me fix this up with be greatly appreciated..



LinkBack URL
About LinkBacks



i think ive gotten ive figured this out for the most part, I just need help with two things. (ill paste my code below)