Saturday, May 22, 2010

Can some1 tell me where im going wrong here, programming in c++ help?

#include %26lt;iostream.h%26gt;


#include %26lt;lvp/random.h%26gt;


void yourturn(int%26amp;total){


int request;


do{


cout%26lt;%26lt;"There are "%26lt;%26lt;total%26lt;%26lt;" stones. How many would you like?"%26lt;%26lt;endl;


cin%26gt;%26gt;request;


if((request%26lt;3||request%26gt;1)||(request%26lt;to...


cout%26lt;%26lt;"Value must be between 1 and 3"%26lt;%26lt;endl;


cout%26lt;%26lt;"How many would you like?"%26lt;%26lt;endl;


cin%26gt;%26gt;request;


}


}while((request%26lt;3||request%26gt;1)||(reques...


total-=request;


return;


}


void myturn(int%26amp;total){


randomize();


int myrequest;


if (total%26gt;4){


cout%26lt;%26lt;"There are "%26lt;%26lt;total%26lt;%26lt;"stones. The computer takes ";


myrequest=random (3)+1;


cout%26lt;%26lt;myrequest;


}


if (total==4){


cout%26lt;%26lt;"There are "%26lt;%26lt;total%26lt;%26lt;"stones. The computer takes ";


myrequest=3;


cout%26lt;%26lt;myrequest;


}


total-=myrequest;


return;


}


int main(){


randomize();


int total=random(30)+15;


while(char answer='Y'){


yourturn(total);


if(total==1){


cout%26lt;%26lt;"THE COMPUTER WINS YOU NOOB";


}


myturn(total);


if(total=1){


cout%26lt;%26lt;"Ok...you beat the computer, woopdidoo";

Can some1 tell me where im going wrong here, programming in c++ help?
I have not tried to execute the program, but I think the following statement has an issue:


In function yourturn(),


if( (request %26lt; 3 || request %26gt;1) ..


ask the user to enter a value between 1 and 3.





If the user enters a valid value like 2, say, then the program would be asking him to re-enter the value.





Instead the check could be something like this:


if( (request %26lt; 1 || request %26gt;3) ...





This would make sure that you are checking for the correct range.





HTH.


No comments:

Post a Comment