problem with scissors, paper, stone

Hi guys. I cant do this right. Please help me.
whatever I type, I always get the loop to repeat. I want the loop to end when i either get sciss, paper or stone as an answer. Otherwise I wanna repeat the loop.

is something wrong with this function?

int human_choice(int choice)
char answer[10];
int x;

printf("sciss, stone or paper?");
scanf("%s", answer);
if (answer=="stone")

else if (answer=="sciss")


else if (answer=="paper")


return answer[10];
You can't compare c-strings like this: answer=="stone"
Instead you need to use function strcmp

Alternatively use C++ std::string. That does allow comparison using "==".
thanks. Now i have another problem
I cant get the statistic right. Do I have to make x,y and z = 0? Even when i do that it still shows the wrong statistic

int statistik(int stat)
int x, y, z;

int winner;

if (stat==2)
else if (stat==3)
else if(stat==1)

if (x>y)
else if (y>x)
else if (x==y)
return winner;
Yeah make them 0 and initialize winner to something. What does this function do ? I couldn't get it to compile unless I did.
You don't initialize x, y or z to any meaningful value. It isn't exactly clear what you're trying to do here.
This statistic is for scissor, paper stone game.
If I win, then X++, if Computer win then Y++.
If draw then Z++.

If i dont put a value in x,y,z then it will automatically take a random value itself.
But if I make them zero, then I think it will start with zero each time i return to this function. And that is not good.
Last edited on
If that's the case, cbeginner, then you'll need to pass the values of x,y,z into the function:

int statistik(int stat,int x,int y,int z)

This way you can specify the values of x y and z and not have to worry about them resetting every time you run the function. If you make them pass by reference, you can even save the values!

int statistik(int stat,int& x,int& y,int& z)
Mukomo: It works. Thank you all guys for ur help.
Topic archived. No new replies allowed.