right so far ive got this to genrate 1 random that the user has to guess and if correct then the program will end what im trying to put in is if the user guess first time or over and over till they get it right to then tell the user how many guess they took to get it right just dunno i tried using a for loop but that didnt work as its giving me 0 any ideas
Code:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string>
int main()
{
std::string pause;
int number;
int max_value = 10, x;
srand( (unsigned)time( NULL ));
rand();
x = rand()/ (RAND_MAX / max_value + 1);
std::cout << "guess the random number between 0 and 10: ";
std::cin >> number;
if (number > x)
std::cout << "number is lower than " << number;
if (number < x)
std::cout << "number is higer than " << number;
for (int i = 0; i < 10; ++i)
{
while (number != x)
{
std::cout << "\n";
std::cout << "try again: ";
std::cin >> number;
if (number > x)
std::cout << "number is lower than " << number;
if (number < x)
std::cout << "number is higer than " << number;
}
std::cout << "Guess is correct";
std::cout << " user took " << i << " tries";
std::cin >> pause;
return 0;
}
}