### problem with scissors, paper, stone

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)
{
int x;

while(true){
printf("sciss, stone or paper?");
clear_stdin();
break;

break;

break;
else
continue;
}

}
You can't compare c-strings like this: `answer=="stone"`
Instead you need to use function strcmp
http://www.cplusplus.com/reference/cstring/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)
x++;
else if (stat==3)
y++;
else if(stat==1)
z++;

while(x+y+z==10){
if (x>y)
winner=1;
else if (y>x)
winner=2;
else if (x==y)
winner=3;
break;
}
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!

IE:
`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.