Code:
////////////////////////////////////////////////////////////////////////////////
//:: Number guessing game
//:: First ever c++ program written by Scott Clarke
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int NumberCheck(int nNumIGuess, int nYourNum, int nNumOfGuesses);
int main()
{
int nNumIGuess = rand() % (1 - 10 + 1); // I'm not gonna fix it, but this rand function
// will always return 1.
int nYourNum;
int nNumOfGuesses = 0; // You have to initialize this variable.
/* Careful with your semicolons on multiline cout statements. */
cout<< "You have three guesses to work out which number I am thinking of " <<
"between 1 - 10. \n Each time you guess I will tell you if the number " <<
"I am thinking of is higher or lower. ";
while (nNumOfGuesses < 3)
{
// You had alot of unnessasary cin statements in here.
cout<<"\nGuess what number I am thinking of? ";
cin>>nYourNum;
NumberCheck(nNumIGuess, nYourNum, nNumOfGuesses);
}
cin.get(); // Trailing cin.get() cause Dev-Cpp closes when it returns a value
}
int NumberCheck(int nNumIGuess, int nYourNum, int nNumOfGuesses)
{
nNumOfGuesses++;
if (nYourNum < nNumIGuess)
{
cout<<"\nIncorrect, the number I am thinking of is higher";
}
else if (nYourNum > nNumIGuess)
{
cout<<"\nIncorrect, the number I am thinking of is lower";
}
else
{
cout<<"\nCorrect!!!! You win";
}
return nNumOfGuesses;
Here you go. Just fix the rand function. I'll leave it up to your logic.