Please use 3 files and make sure it works. Please look over the criteria shows y
ID: 3672052 • Letter: P
Question
Please use 3 files and make sure it works. Please look over the criteria shows you how it should be done.
Compilation errors in your program Program will be rejected. No points.
Not separating your solution into three
files (interface, implementation, and
test files)
-30 points
Do not hard code any user input into
your program. You must prompt for all
input to be provided interactively at
run-time. Otherwise …
-30 points
Your program provides any incorrect
response to the second player’s guesses
-20 points
When the program ends, it outputs
the number of guesses it took to
guess the correct number.
Otherwise…
-10 points
If any code is placed in the Test file
beyond what is needed to
instantiate an object and invoke the
appropriate function(s)…
-30 points
Do not use an instance variable if a
local variable will suffice. For each
unnecessary use of an instance
variable …
-5 points
Allowing the first player to enter a
number that is outside of 0 - 100
-10 points
Any incorrect looping algorithm -20 points
Not terminating the program
correctly, or creating a program that
remains in an infinite loop
-25 points
Thanks
Homepage-CS 1119-91 Con FileProvider%20(1).pdf . | file:///C:/Users/makho/Downloads/FileProvider%20(1).pdf Compilation errors in your program Program will be rejected. No points. Not separating your solution into three-30 points files (interface, implementation, and test files) Do not hard code any user input into your program. You must prompt for all input to be provided interactively at run-time. Otherwise.. Your program provides any incorrect response to the second player's guesses When the program ends, it outputs10 points the number of guesses it took to guess the correct number. Otherwise.. If any code is placed in the Test file-30 points beyond what is needed to instantiate an object and invoke the appropriate function(s)... Do not use an instance variable if a-5 points local variable will suffice. For each unnecessary use of an instance variable Allowing the first player to enter a number that is outside of 0 - 100 Any incorrect looping algorithm Not terminating the program correctly, or creating a program that remains in an infinite loop -30 points -20 points 10 points -20 points 25 points Ask me anything 10:26 AM 2/26/2016 82Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int secretnumber, guess, playagain, remaining_guess = 5;
int guessdiff, minguessdiff = 50, min_number = 1, max_number = 50;
bool win = false;
cout << "Player 1, please choose a secret number between 1-50. ";
cin >> secretnumber;
while(!win) {
cout << "Player 2, please take a guess. ";
do { //Do while loop that validates the guess to be within the bounds.
cout << "The current bounds are " << min_number << " - " << max_number << endl;
cin >> guess;
} while (guess < min_number || guess > max_number);
remaining_guess --;
if(guess == secretnumber) {
cout << "You have guessed the number! You win! ";
cout << "Would you like to play again?(yes=1/no=2) ";
cin >> playagain;
if (playagain == 1) { //Play again sequence, will rerun the entire while loop if user desires.
remaining_guess = 5;
min_number = 1;
max_number = 50;
cout << "Player 1, please choose a secret number between 1-50. ";
cin >> secretnumber;
continue;
} else if (playagain == 2) {
win = true;
}
} else if(guess > secretnumber) {
cout << "Too high, please guess lower than " << guess << endl;
cout << "You have " << remaining_guess << " guesses left, "
<< "please guess again! ";
max_number = guess;
guessdiff = guess - secretnumber;
if (guessdiff <= minguessdiff) {
minguessdiff = guessdiff;
}
} else if(guess < secretnumber) {
cout << "Too low, please guess higher than " << guess << endl;
cout << "You have " << remaining_guess << " guesses left, "
<< "please guess again! ";
min_number = guess;
guessdiff = secretnumber - guess;
if (guessdiff <= minguessdiff) {
minguessdiff = guessdiff;
}
} if(remaining_guess <= 0) {
cout << "Sorry, you are out of guesses! The secret number was "
<< secretnumber << endl;
cout << "Your closest guess was " << minguessdiff << " away. ";
cout << "Would you like to play again?(yes=1/no=2) ";
cin >> playagain;
if(playagain == 1) {
remaining_guess = 5;
min_number = 1;
max_number = 50;
cout << "Player 1, please choose a secret number between 1-50. ";
cin >> secretnumber;
continue;
} else if (playagain == 2) {
win = true;
}
}
}
return 0;
}