1.) you forgot #include<iostream>
2.) int guesscount is never initialized with a maximum number of guesses.
3.) guesscount = guesscount -1 could be --guesscount
4.) Since 'guess' is not a global vairable (it was created inside of int main() i think you will return a new 'guess' back to main from your guessagain() function:
and although global variables are sometimes frowned upon, you could always make guesscount global.. where it can be accessed by any function:
inline int guessagain() //function will return an 'int'
int guess; //declare a local guess variable
cin >> guess; //variable can now be used since it has been declared
guesscount = guesscount -1; //problem here as well, 'guesscount' is also not global.
//i would probably leave this operation in int main()
return guess; //return the user's guess back to main
declare guesscount before int main( ), giving it global scope:
Then whenever a function wants to access this global variable, just precede guesscount with the scope resolution operator.. which will give guesscount global scope outside of the function.
int guesscount = 10;
int main( )
Just keep in mind, the reason people don't like to use global variables... is that they can be easily accessed and changed by any function. I personally think globals are ok.. they are similar to private class member variables with the exception of being limited to only class member functions. I think at this stage in the game, use of globals are o.k. until you learn classes. Remember that all local function variables are destroyed after function execution.. thus the need for some sort of class or global access.
inline int guessagain( ) //function will return an 'int'
cin >> guess;
::guesscount = ::guesscount -1;
then, when you are back inside int main( ), you can make this type assignment (if you wanted to) for example:
int guess = guessagain( ); //Function call returns number of remaining guesses