This is for a final project that in which the project had to contain at least, 1 loop, a class, an array, and file. Im just looking for ideas has to how i could in corporate an array and a file. One idea i had for the array was to use the array to store the round outcomes and then tally the array elements to determine the games winner. Now for a file im not really sure as to how to incorporate. Also if someone is kind enough to look over my code and spot something that im not seeing would really appreciate it. Problem im having is that "You win this round" prints no matter what the outcome is of the round. For example if computer wins it will display "computer wins..." and will also display "You win..." I just need different eyes to see if im over looking something. Thanks for any help.

#include <iostream>
#include <cstdlib>
#include "choiceError.h"
using namespace std;




int main()
{

int compChoice;
int playerChoice;


cout << "Best out of 10 rock, paper, scissor versus the computer!\n";

// Loop to get players decision and computer decision
for (int i=0; i <= 10; i++){
cout << "\nEnter: 1 for rock, 2 for paper, 3 for scissors\n";
cin >>  playerChoice;
	compChoice = 1 + rand() % 3;

	//error hanlder w/ player choice display
	try
	{if ( playerChoice == 0 || playerChoice > 3 )
	throw choiceError();
	
	
	if (playerChoice == 1)
		cout << "\nYou chose: rock" << endl;
	else if (playerChoice == 2)
		cout << "\nYou chose: paper" << endl;
	else 
		cout << "\nYou chose: scissors" << endl;
	
	
}
catch ( choiceError &choiceError)
{
	cout << "Exception occurred: "
		<< choiceError.what() << endl;
}
	// display computer choice
	if (compChoice == 1)
		cout << "Computer chose: rock" << endl;
	else if (compChoice == 2)
		cout << "Compter chose: paper" << endl;
	else 
		cout << "Computer chose: scissors" << endl;

	//display outcome of tie
	if (playerChoice == compChoice)
		cout << "Round is a tie!" <<endl;
	
	//outcomes for computer win
	if (compChoice == 1 && playerChoice == 3)
		cout << "Computer wins this round!" <<endl << endl;
	else if (compChoice == 2 && playerChoice == 1)
		cout << "Computer wind this round!" << endl <<endl;
	else if(compChoice == 3 && playerChoice == 2)
		cout << "Computer wins this round!" <<endl <<endl;

	//outcomes for player win
	else if (playerChoice == 1 && compChoice == 3)
		cout << "You win this round!" << endl << endl;
	else if (playerChoice == 2 && compChoice == 1)
		cout << "You win this round!" << endl << endl;
	else (playerChoice == 3 && compChoice == 2);
		cout << "You win this round!" << endl << endl;
}

system ("pause");
return 0;
}

Line 69: an else statement has no condition, and you have placed a semicolon after it by mistake.

For something that uses a file, try keeping a high score log.

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.