Your variable aiRollResult
is not defined in the scope of the main()
function. It only exists in the scope of the airoll()
function.
Change your airoll()
to
int airoll()
{
int aiRollResult=1+(rand()%6);
cout<<"AI roll: "<<aiRollResult<<endl;
return aiRollResult;
}
Notice the int
return type.
Now you can get the result of the airoll()
in the main function as follows:
int aiRollResult = airoll();
Which will call the airoll()
function and then store the result in the variable. That should solve your problem.
Learn more about functions here:
http://www.cplusplus.com/doc/tutorial/functions/