im working on a program that generates a random number and asks the user to guess what it is. right now im stuck on checking to see if the number is between 1-20. how would i make it continuously loop back until the user enters a number between 1-20? the way im doing it only checks once.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int getData(void);
int getRandom(void);
bool findRange(int);

int main()
    int guessNum, random;
    bool checkRange;
    random = getRandom();
    guessNum = getData();
    checkRange = findRange(guessNum);
    if (checkRange)
        guessNum = getData();
    cout << guessNum << " " << random << endl;
    return 0;

int getData(void)
    int guessNum;
    cout << "I am thinking of a number between 1 and 20.\nCan you guess what it is? : ";
    cin >> guessNum;
    return guessNum;

bool findRange(int guessNum)
    bool answer;
    if (guessNum < 1 || guessNum > 20)
        cout << "\nYour guess is not in the range of 1 - 20.\n\n";
        answer = true;
    return answer;

int getRandom(void)
    int ranNum;
    ranNum = rand() % 22 + 1;

    return ranNum;

>how would i make it continuously loop back
Do you really want me to answer this question? Because if I do, I can guarantee that it won't be pleasant for you.

This article has been dead for over six months. Start a new discussion instead.