I am confused on how to add a counter to my code - I'm writing a 2 player number guessing game and I want to add the number of guesses it took to satisfy the program.
This is what I've got so far:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
{
int x;
int guess;
std::cout << "Enter the number for the player to guess.";
std::cin >> x;
do
{
std::cout << "Enter your guess.";
std::cin >> guess;
if (guess > x)
std::cout << "lower\nEnter your guess.\n";
else if (guess < x)
std::cout << "higher\nEnter your guess.\n";
else
std::cout << "You guessed it!\n";
} while (guess != x);
return 0;
}