ok here is my code

#include <iostream>
#include <ctime>
using namespace std;

int main(void)
{
	char cName[81] = "",
		cUser[9] = "",
		szComp[9] = "",
		szr[5] = "Rock",
		szp[6] = "Paper",
		szs[9] = "Scissors";
	int	 cComp = 0;
	srand(static_cast<unsigned int>(time(0)));
	cComp = rand()%3;
	if (cComp == 0)
		strcpy_s(szComp,szr);
	if (cComp == 1)
		strcpy_s(szComp,szp);
	if (cComp == 2)
		strcpy_s(szComp,szs);

	cout << "The game of paper, rock and scissors is played by having each player" << endl
		<< "select either paper, rock, or scissors as their move for each round." << endl
		<< "A winner is determined by the combination that was played, where paper" << endl
		<< "covers rock and wins, scissors cuts paper and wins, or rock smashes" << endl
		<< "scissors and wins. You will play one round of this game." << endl << endl;

	cout << "please enter your name: ";
	cin.getline(cName, 81);
	cin.ignore(cin.rdbuf() ->in_avail());
	cout << endl << "have fun, " << cName << "!" << endl << endl
		<< "Press Any Key to Continue" << endl << endl;

	cout << cName << ", Please select rock, paper or scissors..." << endl << endl
		<< "Rock" << endl << "Paper" << endl << "Scissors" << endl;
	cout << "Your Selection: ";
	cin.getline(cUser, 9);	
	cout << cName << " has played " << cUser << endl
		<< "The computer has played " << szComp << endl;
	switch(cUser)
	{
	case 'Rock':
		if (szComp == "Rock")
			cout << "Its a Tie." << endl;
		if (szComp == "Paper")
			cout << "Sorry you lose." << endl;
		if (szComp == "Scissors")
			cout << "You Win." << endl;
		break;

	case 'Paper':
		if (szComp == "Rock")
			cout << "You Win." << endl;
		if (szComp == "Paper")
			cout << "Its a Tie." << endl;
		if (szComp == "Scissors")
			cout << "sorry You lose." << endl;
		break;
	case "Scissors":
		if (szComp == "Rock")
			cout << "Sorry you lose." << endl;
		if (szComp == "Paper")
			cout << "You Win." << endl;
		if (szComp == "Scissors")
			cout << "Its a Tie." << endl;
		break;
	}
	cin.get();
	return 0;
}

i am currently getting 3 errors and i dont know what to do

Recommended Answers

All 2 Replies

>i am currently getting 3 errors
They're telling you that you can't use an array as the condition for a switch statement. You can only use integral values (or char, because char is an integral type).

Not only that but for strings you appear to be using ' rather than ". While neither method will work ...
Since you're using C++ you might as well use std::string rather than character arrays. Try an if-else if ladder rather than a switch.

#include <string>

//...

std::string str;
std::cout<< "Enter something: ";
std::getline( std::cin, str );

if ( str == "something" )
  std::cout<< "str == something!";
else
  std::cout<< "Not anything";
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.