I'm running this code in Visual C++ 6.0 and it won't run correctly.. need some expert help..
I don't know what's wrong with this code..
Thanks for the help in advance..

# include <iostream>
using namespace std;

int main()
{

	char  one, two, answer;

	do {

	system("cls");

	cout<<"\n\n\t\tSelect a key from the following choices:";
	cout<<"\n\n\t\t\tKey:\t\tMeaning:";
	cout<<"\n\n\t\t\t P\t\t paper";
	cout<<"\n\t\t\t R\t\t rock";
	cout<<"\n\t\t\t S\t\t scissor";

	cout<<"\n\nEnter player 1:";
	cin>>one;

	cout<<"Enter player 2:";
	cin>>two;

	if (one=='P'||'p' && two=='P'||'p')
       {  
	    cout<<"\nResult: Tie!\nNobody wins!";
	   }
	else if (one=='R'||'r' && two=='R'||'r')
	   { 	
		cout<<"\nResult: Tie! \nNobody wins!";
	   }
	else if (one=='S'||'s' && two=='S'||'s')
	   {
		cout<<"\n Result: Tie! \nNobody wins!";
	   }
	else if (one=='P'||'p' && two=='R'||'r')
	   {
		cout<<"\n\nResult: Player 1 wins! \n Basis: Paper Covers Rock!";
	   }
	else if (one=='R'||'r' && two=='S'||'s')
	   {
		cout<<"\nResult: Player 1 wins! \n Basis: Rock Breaks Scissor!";
	   }
	else if (one=='S'||'s' && two=='P'||'p')
	   {
		cout<<"\nResult: Player 1 wins! \n Basis: Scissor Cuts Paper!";
	   }
	else if (one=='R'||'r' && two=='P'||'p')
	   {
		cout<<"\n\nResult: Player 2 wins! \n Basis: Paper Covers Rock!";
	   }
	else if (one=='S'||'s' && two=='R'||'r')
	   {
		cout<<"\nResult: Player 2 wins! \n Basis: Rock Breaks Scissor!";
	   }
	else if (one=='P'||'p' && two=='S'||'s')
	   {
		cout<<"\nResult: Player 2 wins! \n Basis: Scissor Cuts Paper!";
	   }
    else
	   {
		cout<<"Wrong output!";
	   }

	cout<<"\t\n\n\nWould you like to play again? y/n:";
	cin>>answer;
	
	}
	while (answer=='Y'||'y');
	return 0;
}





I also tried this but the result is the same..
Where did i go wrong?
Help please..


# include <iostream>
using namespace std;

main()
{

	char  one, two, answer;

	do {

	system("cls");

	cout<<"\n\n\t\tSelect a key from the following choices:";
	cout<<"\n\n\t\t\tKey:\t\tMeaning:";
	cout<<"\n\n\t\t\t P\t\t paper";
	cout<<"\n\t\t\t R\t\t rock";
	cout<<"\n\t\t\t S\t\t scissor";

	cout<<"\n\nEnter player 1:";
	cin>>one;

	cout<<"Enter player 2:";
	cin>>two;

	if (one=='P'||one=='p' && two=='P'||two=='p')
       {  
	    cout<<"\nResult: Tie!\nNobody wins!";
	   }
	else if (one=='R'||one=='r' && two=='R'||two=='r')
	   { 	
		cout<<"\nResult: Tie! \nNobody wins!";
	   }
	else if (one=='S'||one=='s' && two=='S'||two=='s')
	   {
		cout<<"\n Result: Tie! \nNobody wins!";
	   }
	else if (one=='P'||one=='p' && two=='R'||two=='r')
	   {
		cout<<"\n\nResult: Player 1 wins! \n Basis: Paper Covers Rock!";
	   }
	else if (one=='R'||one=='r' && two=='S'||two=='s')
	   {
		cout<<"\nResult: Player 1 wins! \n Basis: Rock Breaks Scissor!";
	   }
	else if (one=='S'||one=='s' && two=='P'||two=='p')
	   {
		cout<<"\nResult: Player 1 wins! \n Basis: Scissor Cuts Paper!";
	   }
	else if (one=='R'||one=='r' && two=='P'||two=='p')
	   {
		cout<<"\n\nResult: Player 2 wins! \n Basis: Paper Covers Rock!";
	   }
	else if (one=='S'||one=='s' && two=='R'||two=='r')
	   {
		cout<<"\nResult: Player 2 wins! \n Basis: Rock Breaks Scissor!";
	   }
	else if (one=='P'||one=='p' && two=='S'||two=='s')
	   {
		cout<<"\nResult: Player 2 wins! \n Basis: Scissor Cuts Paper!";
	   }
    else
	   {
		cout<<"Wrong output!";
	   }

	cout<<"\t\n\n\nWould you like to play again? y/n:";
	cin>>answer;
	
	}
	while (answer=='Y'||answer'y');
	return 0;
}

your problem is cin>>char_var;
Why? When you enter something on your keyboard and then press enter you have entered more characters. eg:
YOU ENTER: p
CHARS IN BUFFER: p, '\n'
That '\n' is from the enter you pressed, and you have to get rid of it before next input.

So, after every cin insert: cin.ignore(); That will work if you only enter one digit (p, or s...)
If you want it to work even if you write a novell ( :) ) write: cin.ignore(numeric_limits<streamsize>::max(), '\n'); HTH

while (answer=='Y'||'y');

Is like saying
"WHILE ANSWER IS 'Y' OR "

"WHILE 'y'" <-- What's 'y'?

Your while loop isn't terminating. I'm sure the myriad of if statements using this logic are failing too.

Try this instead:

while(answer=='Y' || answer=='y')

Yikes. Also, when you're doing the checks for the P, S, and R,

if (one=='p' || one=='P' && two=='p' || two == 'P')

if one is 'p', its going to be true and skip the rest of the condition

a workaround to this is to check for uppercase inputs and convert them to lowercase, then use those in the comparisions

if(one=='P')
    one = 'p'
...
if(one=='p' && two='p')
   cout << "tie . . .";
...
# include <iostream>
using namespace std;

int main()
{

	char one, two, answer;

	do {

		system("cls");

		cout<<"\n\n\t\tSelect a key from the following choices:";
		cout<<"\n\n\t\t\tKey:\t\tMeaning:";
		cout<<"\n\n\t\t\t P\t\t paper";
		cout<<"\n\t\t\t R\t\t rock";
		cout<<"\n\t\t\t S\t\t scissor";

		cout<<"\n\nEnter player 1:";
		cin>>one;
        cin.ignore(); 
        if(one=='P')
            one='p';
        if(one=='R')
            one='r';
        if(one=='S')
            one='s';
        
        
		cout<<"Enter player 2:";
		cin>>two;
        cin.ignore(); 
        if(two=='P')
            two='p';
        if(two=='R')
            two='r';
        if(two=='S')
            two='s';
            
		if (one=='p' && two=='p')
		{
			cout<<"\nResult: Tie!\nNobody wins!";
		}
		else if (one=='r' && two=='r')
		{
			cout<<"\nResult: Tie! \nNobody wins!";
		}
		else if (one=='s' && two=='s')
		{
			cout<<"\n Result: Tie! \nNobody wins!";
		}
		else if (one=='p' && two=='r')
		{
			cout<<"\n\nResult: Player 1 wins! \n Basis: Paper Covers Rock!";
		}
		else if (one=='r' && two=='s')
		{
			cout<<"\nResult: Player 1 wins! \n Basis: Rock Breaks Scissor!";
		}
		else if (one=='s' && two=='p')
		{
			cout<<"\nResult: Player 1 wins! \n Basis: Scissor Cuts Paper!";
		}
		else if (one=='r' && two=='p')
		{
			cout<<"\n\nResult: Player 2 wins! \n Basis: Paper Covers Rock!";
		}
		else if (one=='s' && two=='r')
		{
			cout<<"\nResult: Player 2 wins! \n Basis: Rock Breaks Scissor!";
		}
		else if (one=='p' && two=='s')
		{
			cout<<"\nResult: Player 2 wins! \n Basis: Scissor Cuts Paper!";
		}
		else
		{
			cout<<"Wrong output!";
		}

		cout<<"\t\n\n\nWould you like to play again? y/n:";
		cin>>answer;
        cin.ignore(); 
	}
	while (answer=='Y'|| answer=='y');
	return 0;
}
This article has been dead for over six months. Start a new discussion instead.