hey ..

i write this code .. but i have errors .. i think because i didn't use the enum in the right way?! .. can anyone tell my how to correct it ..

i got these errors :( .. :
'stone' : redefinition; different basic types
see declaration of 'stone'
same errrors with scissors and paper
and
'getuser1': member function definition looks like a ctor, but name does not match enclosing class
same error with getuser2
and unexpected end of file found

this is the code ..

#include<iostream>

using namespace std;

class fun
    {
private:

	enum User1{stone,scissors,paper};
	enum User2{stone,scissors,paper};

public:

	void setuser1(enum u1){
	User1 = u1;	
	}

	enum getuser1(){
	return User1 ;	
	}

	void setuser2(enum u2){
	User2 = u2;	
	}

	enum getuser2(){
	return User2 ;	
	}

	void display(){
                cout<< " the first player choose " << getuser1() << endl;
                 cout<< " the second player choose " << getuser2() << endl;
	}

	int wins(){
	int score_u1=0;
      	int score_u2=0;

   for (int i=0,score_u1 < 3 || score_u2 < 3,i++){
     if ( getuser1() == getuser2() )
	return 0;
     else if(getuser1()== stone && getuser2()==scissors){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==paper && getuser2()==stone){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==stone && getuser2()==scissors){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==paper && getuser2()==stone){
   	  score_u2=1;
	  return 2;}
	}
     };

int main(){
    fun play;
    enum u1 {stone,scissors,paper};
    enum u2 {stone,scissors,paper};
    cout<<"first player .. please enter your choies";
    cin>>u1;
    cout<<"second player .. please enter your choies";
    cin>>u2;

    play.setuser1(u1);
    play.setuser2(u2);
    play.getuser1();
    play.getuser2();
    play.display();

switch ( play.wins() )
{
case 1 :
  cout<< " the first player wins ";
	break;
case 2 :
cout<< " the second player wins ";
break;
case 0 :
cout<< " It's a tie ";
break;
case -1 :
cout << " error ";
break; }

      return 0;
    }

thanx :)

Rename the enums like User1_stone ,User2_stone or else use only one enum.

but i still have the paper and scissors what i do with them ? .. and how to use one enum 4 user1 and user2 ?

enum getuser1(){ <<< wrong User1 getuser1() <<< right

Are you REQUIRED to use enums in this assignment? If not then it would probably be easier just to use const int for each

const int stone = 1;
const int paper = 2;
const int scissors = 3;
...
...
int getuser1();

yes i have to use enum in this .. i write it again and fixed some of it .. but still have errors ..

'stone' : redefinition; different basic types
see declaration of 'stone'
same errrors with scissors and paper

#include<iostream>

using namespace std;

class fun
    {
private:

	enum U1{stone,scissors,paper}User1;
	enum U2{stone,scissors,paper}User2;

public:

	void setuser1(user_1 u1){
	User1 = u1;	
	}

	U1 getuser1(){
	return User1 ;	
	}

	void setuser2(user_2 u2){
	User2 = u2;	
	}

	U2 getuser2(){
	return User2 ;	
	}

	void display(){
                cout<< " the first player choose " << getuser1() << endl;
                 cout<< " the second player choose " << getuser2() << endl;
	}

	int wins(){
	int score_u1=0;
      	int score_u2=0;

   for (int i=0,score_u1 < 3 || score_u2 < 3,i++){
     if ( getuser1() == getuser2() )
	return 0;
     else if(getuser1()== stone && getuser2()==scissors){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==paper && getuser2()==stone){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==stone && getuser2()==scissors){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==paper && getuser2()==stone){
   	  score_u2=1;
	  return 2;} }
	}
     };

int main(){
    fun play;
    enum user_1{stone,scissors,paper}u1;
    enum user_2{stone,scissors,paper}u2;

    cout<<"first player .. please enter your choies";
    cin>>u1;
    cout<<"second player .. please enter your choies";
    cin>>u2;

    play.setuser1(u1);
    play.setuser2(u2);
    play.getuser1();
    play.getuser2();
    play.display();

switch ( play.wins() )
{
case 1 :
  cout<< " the first player wins ";
	break;
case 2 :
cout<< " the second player wins ";
break;
case 0 :
cout<< " It's a tie ";
break;
case -1 :
cout << " error ";
break; }

      return 0;
    }

How about

enum objType {stone,scissors,paper};
	objType User1;
	objType User2;

That's generating actual objects called User1 and User2. What you want to do is typedef them

enum objType {stone,scissors,paper};
typedef objType U1;
typedef objType U2;

>>That's generating actual objects called User1 and User2. What you want to do is typedef them

But why does he want two user defined types with exactly the same innards? Why not two objects/variables of a single type?

i'm sorry .. but i don't understand this way ..

i try again but still have error:

'=' : cannot convert from 'int' to 'enum fun::U1'

#include<iostream>

using namespace std;

class fun
    {
private:

	enum U1{stone=0,scissors,paper}User1,User2;

public:

	void setuser1(int ch1){
	User1 = ch1;	
	}

	U1 getuser1(){
	return User1 ;	
	}

	void setuser2(int ch2){
	User2 = ch2;	
	}

	U1 getuser2(){
	return User2 ;	
	}

	void display(){
                cout<< " the first player choose " << getuser1() << endl;
                 cout<< " the second player choose " << getuser2() << endl;
	}

	int wins(){
	int score_u1=0;
      	int score_u2=0;

   for (int i=0;score_u1 < 3 || score_u2 < 3;i++){
     if ( getuser1() == getuser2() )
	return 0;
     else if(getuser1()== stone && getuser2()==scissors){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==paper && getuser2()==stone){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==stone && getuser2()==scissors){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==paper && getuser2()==stone){
   	  score_u2=1;
	  return 2;} }
	}
     };

int main(){
    fun play;
	int ch1,ch2;

    cout<<"first player .. please enter your choies 0 for stone and 1 for scissors , 2 for paper";
    cin>> ch1;
    cout<<"second player .. please enter your choies 0 for stone and 1 for scissors , 2 for paper";
    cin>> ch2;

    play.setuser1(ch1);
    play.setuser2(ch2);
    play.getuser1();
    play.getuser2();
    play.display();

switch ( play.wins() )
{
case 1 :
  cout<< " the first player wins ";
	break;
case 2 :
cout<< " the second player wins ";
break;
case 0 :
cout<< " It's a tie ";
break;
case -1 :
cout << " error ";
break; }

      return 0;
    }

:(

your code contains a lot of syntax errors. Plus the formatting stinks. Here's the cleanup of syntax errors.

class fun
    {
public:
	enum U1{stone=0,scissors,paper};

private:

	U1 User1,User2;

public:

	void setuser1(U1 ch1){
	User1 = ch1;	
	}

	U1 getuser1(){
	return User1 ;	
	}

	void setuser2(U1 ch2){
	User2 = ch2;	
	}

	U1 getuser2(){
	return User2 ;	
	}

	void display(){
                cout<< " the first player choose " << getuser1() << endl;
                 cout<< " the second player choose " << getuser2() << endl;
	}

	int wins(){
	int score_u1=0;
      	int score_u2=0;

   for (int i=0;score_u1 < 3 || score_u2 < 3;i++){
     if ( getuser1() == getuser2() )
	return 0;
     else if(getuser1()== stone && getuser2()==scissors){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==paper && getuser2()==stone){
	  score_u1+=1;
	  return 1;}
     else if(getuser1()==stone && getuser2()==scissors){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==scissors && getuser2()==paper){
	  score_u2=1;
	  return 2;}
     else if(getuser1()==paper && getuser2()==stone){
   	  score_u2=1;
	  return 2;} }
   return 0;
	}
     };

int main(){
    fun play;
	int ch1,ch2;

    cout<<"first player .. please enter your choies 0 for stone and 1 for scissors , 2 for paper";
    cin>> ch1;
    cout<<"second player .. please enter your choies 0 for stone and 1 for scissors , 2 for paper";
    cin>> ch2;
//
// TODO:  Add some error checking here to insure theat ch1 and ch2 are in range
//
//
    play.setuser1(static_cast<fun::U1>(ch1));
    play.setuser2(static_cast<fun::U1>(ch2));
    play.getuser1();
    play.getuser2();
    play.display();

switch ( play.wins() )
{
case 1 :
  cout<< " the first player wins ";
	break;
case 2 :
cout<< " the second player wins ";
break;
case 0 :
cout<< " It's a tie ";
break;
case -1 :
cout << " error ";
break; }

      return 0;
    }

thanx aloooot really 4 ur help Ancient Dragon .. i really thinking that i'll start lose my mind before i can solve this lool :D

thanx alot again .. :) .. and thanx 4 everyone who's try to help me :)

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.