I'm just wondering if anyone can take a look at my current program below and see what im missing. ive been working on it for so long that i'm just stuck and need another help to kind of get me going in the right direction.

I'm trying to create the Paper/Rock/Scissors game, but CANT get the computer to generate random outputs.

the objective: user inputs R (rock), P (paper), S (scissors) or Q (quit).
computer is then to automatically play the game with user.
the winner is determined, etc.

problem: how do i get to generate the computer to play with the user?!

limits/restrictions: i am currently in a beginner's c++ class. the furthest we've gone are Subprograms, Voids, Value-Returning Functions. Teacher wants us to use such tools to create the game.

The program below runs and compiles properly, but of course, the computer doesn't output anything because i have no idea how to come about including the computer to think for its own. I'm slowly giving up, but i cant stop thinking about it. i hope someone can help me. any suggestion would be greatly appreciated. thank you.


#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

void results();
char human();
char computer();

char human()
  char humchoice;

  while (true)
    cout << " " << endl;
    cout << "Choose [R-Rock, P-Paper, S-Scissors, Q-Quit]: ";
    cin >> humchoice;

    if (humchoice == 'Q' || humchoice == 'q') break;
    if (humchoice == 'R' || humchoice == 'r') break;
    if (humchoice == 'P' || humchoice == 'p') break;
    if (humchoice == 'S' || humchoice == 's') break;
    cout << " INVALID ENTRY. Try again..." << endl;
  return humchoice;
} // human

char computer()
  char compchoice = rand()%3;

  return compchoice;

void results()

int main ()

  // initialize the computer's random number generator

  // declare variables
  char humchoice;
  char compchoice;

  // start loop
  while (true)

    // determine computer's choice
    compchoice = computer();

    // prompt for, and read, the human's choice
    humchoice = human();

    // if human wants to quit, break out of loop
    if (humchoice == 'Q' || humchoice == 'q') break;

  // print results
  cout << "Computer: " << compchoice << endl;
  cout << "Human: " << humchoice << endl;

  // end loop

  // end program
  return 0;
} // main
7 Years
Discussion Span
Last Post by iamthwee
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.