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 :)