Hello All,

I need some major help. I have to make a game for my final project. I decided to do Rock, paper, scissors. I need to add 2 arrays, repetition, user defined functions, and an option to quit. Like "type 3 to quit" Please help. Here is my code:

let me know what you think:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>

using namespace std;
int main()

{
	ifstream inData;
	ofstream outData;

	inData.open("a:\\prog.dat");
	outData.open("a:\\prog.out");

    srand((unsigned)time(0));
    int choice;
    int compchoice = (rand()%2)+1;

		
    cout << "Are you ready to play Rock, Paper, Scissors?!!";
    cout << " Let Start! You opponent will be the computer. Type 0 for";
    cout << " rock, 1 for paper, and 2 for scissors\n";
    cin >> choice;
   
    if (choice == 0) 
    {
              if (compchoice == 0)
              cout << "It's a tie!\n\n\n\n";
              else if (compchoice == 1)
              cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
              else if (compchoice == 2)
              cout << "Rock beats scissors! You win!\n\n\n\n";
    }
    
    if (choice == 1)
    {
               if (compchoice == 0)
               cout << "It's a tie!\n\n\n\n";
               else if (compchoice == 1)
               cout << "Paper beats rock! You win!\n\n\n\n";
               else if (compchoice == 2)
               cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
   }
   
   if (choice == 2)
   {
              if (compchoice == 0)
              cout << "It's a tie!\n\n\n\n";
              else if (compchoice == 1)
              cout << "Scissors beat paper! You win!\n\n\n\n";
              else if (compchoice == 2)
              cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
   }
   inData.close();
    	outData.close();

    return main();
}

Recommended Answers

All 5 Replies

Read about using code tags when posting code to this board or risk restricting the number of responses from quality responders.

return main(); //OUCH!

Read up on loops and use an int called flag to control it after telling the user they could enter 3 to stop the game.

let me know what you think

Terrible. Never call main() !!!! Use a loop. And CODE tags. They were mentioned in the rules you read when you registered. (You did read them, didn't you?)

Also, you have no repetition, no user defined functions, and no option to quit. You didn't follow the design required.

Hello,

I know I do not have those things. That is what I was asking help with because reading about it does not help me that much. To see examples does, THANKS

Hope this helps.

>>repetition

int main()
{
    while(true)  // start of loop
    {
          // repeat code goes here

    } // end of loop
}

>>no user defined functions
Just a function you write yourself. Call it anything you wish except main

int userDefinedFunction()
{
   cout << "This is a user defined function\n";
   return 0;
}

>>and no option to quit

int main()
{
   char option;
    while(true)  // start of loop
    {
          cout << "Press 'Q' to quit\n";
          cin >> option;
          if( option == 'Q')
                break;
          // repeat code goes here

    } // end of loop
}
display menu
input choice
while choice != quit
[
    computer = random-value
    call function TestForWin"  (returns 0 for computer win, 1 for user win)
    Output message based on the return value
    output menu
    input choice
]
exit program

function TestForWin"  (parameters computer and user choices)
[
    winner = (decide who wins)
    return winner
]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.