1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
if (strcmp (argv[1], "-n") == 0 && strcmp (argv[3], "-d") == 0) //if user inputs order -n X -d difficulty
{
int i;
float j;
i = atoi (argv[2]); //convert string into integer
srand (time(NULL));
int x, y = rand() % i;
if (strcmp (argv[4], "easy") == 0)
j = 0.8;
if (strcmp (argv[4], "medium") == 0)
j = 0.6;
if (strcmp (argv[4], "hard") == 0)
j = 0.4;
if (strcmp (argv[4], "unlimited") == 0)
j = 1000;
cout << "I'm thinking of a number between 0 and " << i << ". Can you guess it?" << endl;
{
for (int a = j*log2(i); a > 0 ; a--)
{
cin >> x;
if (x > y)
cout << "I'm thinking of a smaller number. Please try again." << endl;
else
if (x < y)
cout << "I'm thinking of a larger number. Please try again." << endl;
if (x == y)
goto correct;
else;
}
cout << "Out of tries! You lost." <<endl;
return 0;
}
correct:
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
if (strcmp (argv[1], "-d") == 0 && strcmp(argv[3], "-n") == 0) //if the user inputs order -d diff -n x
{
int i;
float j;
i = atoi (argv[4]); //convert string into integer
srand (time(NULL));
int x, y = rand() % i;
if (strcmp (argv[2], "easy") == 0)
j = 0.8;
if (strcmp (argv[2], "medium") == 0)
j = 0.6;
if (strcmp (argv[2], "hard") == 0)
j = 0.4;
if (strcmp (argv[2], "unlimited") == 0)
j = 1000;
cout << "I'm thinking of a number between 0 and " << i << ". Can you guess it?" << endl;
{
for (int a = j*log2(i); a > 0 ; a--)
{
cin >> x;
if (x > y)
cout << "I'm thinking of a smaller number. Please try again." << endl;
else
if (x < y)
cout << "I'm thinking of a larger number. Please try again." << endl;
if (x == y)
goto correct1;
else;
}
cout << "Out of tries! You lost." <<endl;
return 0;
}
correct1:
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
if (strcmp (argv[1], "-n") == 0 && strcmp (argv[3], "-d") != 0) //if the user inputs -n X
{
int i;
i = atoi (argv[2]); //convert string into integer
srand (time(NULL));
int x, y = rand() % i;
cout << "I'm thinking of a number between 0 and " << i << ". Can you guess it?" << endl;
do
{
cin >> x;
if (x > y)
cout << "I'm thinking of a smaller number. Please try again." << endl;
else
if (x < y)
cout << "I'm thinking of a larger number. Please try again." << endl;
}
while (x != y);
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
if (strcmp (argv[1], "-d") == 0 && strcmp(argv[3], "-n") != 0) //if the user inputs -d difficulty
{
float j;
srand (time(NULL));
int x, y = rand() % 101;
if (strcmp (argv[2], "easy") == 0)
j = 0.8;
if (strcmp (argv[2], "medium") == 0)
j = 0.6;
if (strcmp (argv[2], "hard") == 0)
j = 0.4;
if (strcmp (argv[2], "unlimited") == 0)
j = 1000;
cout << "I'm thinking of a number between 0 and 100. Can you guess it?" << endl;
{
for (int a = j*log2(100); a > 0 ; a--)
{
cin >> x;
if (x > y)
cout << "I'm thinking of a smaller number. Please try again." << endl;
else
if (x < y)
cout << "I'm thinking of a larger number. Please try again." << endl;
if (x == y)
goto correct2;
else;
}
cout << "Out of tries! You lost." <<endl;
return 0;
}
correct2:
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
if (argc == 1) //blank input
int i;
srand (time(NULL));
int x, y = rand() % 101;
cout << "I'm thinking of a number between 0 and 100. Can you guess it?" << endl;
do
{
cin >> x;
if (x > y)
cout << "I'm thinking of a smaller number. Please try again." << endl;
else
if (x < y)
cout << "I'm thinking of a larger number. Please try again." << endl;
}
while (x != y);
cout << "Correct! You guessed the secret number!" << endl;
return 0;
}
|