Hi:
I am practicing using a recursive function. I created a guess my number game. The program randomly generates a number in main() and then passes this into the recurse function. I call the recurse function from main.
1) The error message is placed in the code.
2) I declared the user variable input number inside of the recurse function instead of passing this in. I tried to pass in but then there was an error message that there were too many arguements.
Code:void recurse (int iGuessIn) { //Number input by user. int iNumberIn = 0; cin>>iNumberIn; system("pause"); if (iGuessIn < iNumberIn) { //Error message here reporting "error primary-expression before '<<' token." cout<<"Sorry. Wrong guess. Try again. "; <<endl; cin>>iNumberIn; system("pause"); recurse (iGuessIn, iNumberIn); }//if else if (iGuessIn > iNumberIn) { cout<<"Sorry. Wrong guess. Try again. "; <<endl; recurse (iGuessIn, iNumberIn); }//else if else (iGuessIn == iNumberIn) { cout<<"Correct! My number was "; <<iGuessIn; <<endl; return; }//else }//recurse



LinkBack URL
About LinkBacks



