What are the source codes for the following 3 programs: In this game, the comput
ID: 3650191 • Letter: W
Question
What are the source codes for the following 3 programs:
In this game, the computer picks a random number in the range 0 to 99, and then the user is allowed eight triesto guess what it is. After each wrong guess, the computer responds by reporting whether that guess was too highor too low.
2. Implement the guessing game described above. Use a for loop that iterates eight time. Use
System.exit(0) inside the loop if the user guesses correctly.
Here is a sample run where the user guesses correctly:
I am thinking of a number from 0 to 99.
You have up to eight tries to guess what it is.
Guess #0: 50
No, that's too low.
Guess #1: 75
No, that's too low.
Guess #2: 87
No, that's too high.
Guess #3: 81
You got it! It was 81.
And here is a sample run where the user fails to guess correctly:
I am thinking of a number from 0 to 99.
You have up to eight tries to guess what it is.
Guess #0: 30
No, that's too low.
Guess #2: 40
No, that's too low.
Guess #3: 50
No, that's too low.
Guess #4: 60
No, that's too low.
Guess #5: 70
No, that's too high.
Guess #6: 66
No, that's too low.
Guess #7: 67
No, that's too low.
Sorry. You failed to guess 68.
The Discrete Binary Logarithm
Recall that the logarithm with base b of a number x is the exponent on b that equals x: by = x. It is written as
y = logb x. If the base b = 10, then it is called the common logarithm, and usually written y = logx for 10y = x. If
the base b = e ? 2.718281828459, then it is called the natural logarithm, and usually written y = lnx for ey = x.
If the base is b = 2, then it is called the binary logarithm, and is usually written y = lg x for 2y = x. Computer
scientists usually use the binary logarithm.
The discrete binary logarithm (dbl) of a number x is the greatest integer not exceeding lg x. That is the
greatest integer n for which 2n ? x. For example, the dbl of 21 is 4, because 24 ? 26 < 25. Mathematically, the
dbl would be is written as
dbl(x) = ?lgx?
The symbol ? ? denotes the floor function, which simply means,
Explanation / Answer
#include #include #include #include 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; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.