Hi, I have a programming project in which I have to create a game where the user can select the upper bound of numbers and difficulty they want and then guess the secret number within that bound and difficulty.
So far, this is my code. It compiles and allows the user to select the upper bound.
However, I am having trouble adding difficulty levels to my game. The difficulty levels limit the number of guesses the user has: easy giving 20 guesses, medium giving 10, hard giving 5.
The user must be able to choose the difficulty as a command line parameter. Thus if the program is run as "./guess -d easy" it will play the easy mode. Does anyone have any ideas on how I should do this?
I tried doing an if statement with:
if (argc=='easy') but I don't know where to go from there.
or a for loop with:
for (int guesses=10; guesses <=10; guesses--) but it doesn't work.
#include <iostream>
#include <time.h>
#include <cmath>
using namespace std;
int main(int argc, char **argv)
{
cin >> argc;
if (argc== argc)
do {
int secret_number;
int guesses;
int user_guess;
srand ( time(NULL) );
int upper_bound=argc;
secret_number= rand () % upper_bound;
cout << secret_number;
do
{
cout << "I'm thinking of a number between 0 and " << upper_bound <<". Can you guess it?" << endl;
cin >> user_guess;
if (user_guess>secret_number)
cout << "I'm thinking of a smaller number. Please try again" << endl;
else if (user_guess<secret_number)
cout << "I'm thinking of a larger number. Please try again" << endl;
}
while (user_guess!=secret_number);
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
while (argc==argc);
}
Thanks