Looping For Input

closed account (365X92yv)
I've got a program I'm trying to write that generates a random number and then asks the user to try to guess that number. I've got it to run with if else code but I want to swap out the if else statements for a while loop and have it keep asking for user input until the user guesses right. I know this is quite a bit trivial as far as what this community may put out but I'm down to the wire on this project and I need it done asap. Thanks for any help you guys have for me.

Hard Line Coded
closed account (365X92yv)
/////////////////////////////////////////
// xxxxxxxxxxxxxxxxx
// CMPE 1370/1170
//
//
// Guessing Game // Version 2
/////////////////////////////////////////

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string>

using namespace std;

void intro()
{
cout << "Welcome to the guessing game!" << endl;
cout << "I'll pick a number from 1 to 10. Try to guess it." << endl;
cout << "Okay, I've got my number." << endl << "What's your guess? ";

}

void outro()
{
cout << "Thanks for playing." << endl;
}

string guessCheck(int randNum)
{
int guess;
cin >> guess;
string response;
while(guess != randNum)
{

response = "Nope, thats not it. Guess again: ";
cin >> guess;

}
}

int main( )
{
int secret_number;
string validatedGuess;
srand(static_cast<int>(time(NULL)));
secret_number = rand() % 10 + 1;
intro();

validatedGuess = guessCheck(secret_number);
cout << validatedGuess;

outro();
system("pause");
return 0;
}
_______________________________________________________________

Trying to get the guessCheck function to run a while loop and if guess is not equal to randNum, then have it re-ask me for another guess.
Topic archived. No new replies allowed.