/*Goal: In the programming quiz, use a while loop to prompt
**the user to guess a target number. 
**Tell the user if the guess is too high or too low. 
**The user enters -1  or guesses the target number to end 
**the program.
*
*  To compile: $ g++ -o whileLoop whileLoop.cpp
*  To executeL $ ./whileLoop
*
*/



#include <iostream>
#include <sstream>
#include <time.h> //added for the random number generator seed
#include <cstdlib>//added to use the rand function

int main()
{
    //use 55 as the number to be guessed
    int targetguess;
    int guess = -1;
    std::string userString;

    srand(time(NULL));  //set the seed for the random number generator
    targetguess = rand() %100 + 1; //generate the 'random' number

    while(guess != targetguess)
    {
        std::cout<<"Guess a number between 0 and 100: ";

        std::getline (std::cin,userString);

        //convert to an int
        std::stringstream(userString) >> guess;

        std::cout << userString << "\n";

        if(guess > targetguess)
            std::cout<<"Your guess is too high\n";
        else if(guess < targetguess)
            std::cout<<"Your guess is too low\n";
        else
            std::cout<<"You guessed the target!\n";

        if(guess == -1)
        {
            std::cout<<"good bye!";
            break;
        }
    }

    return 0;
}