Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the answer as soon as possible. A correct answer will receive a like. Strict warning: AI responses are unacceptable. DK 1 6

I need the answer as soon as possible. A correct answer will receive a like. Strict warning: AI responses are unacceptable.
DK16
"c++ code
Please edit the code below with these additional steps:
Keep track of how many guesses the user made to guess the random target number and output one line to a file score.txt [like ""last player took 7 guesses to guess the correct number.""
Begin each game by reading the file score.txt to input a message of how many guesses the last player took to guess the correct number and output that information to the user, or if the file is empty, output a message that no player has played the game yet. Make sure you create the file score.txt first and have it empty the first time the game is played
//libraries
#include
#include
#include
#include
#include
using namespace std;
//Programmer defined data types
//Special compiler dependent definitions
//NONE
//global constants/variables
//NONE
//Programmer defined functions
void introduction(string obj, string ins); //user introduction
bool isRepeatedGuess(int uGuess,int guesses[],int nGuesses); //repeated guesses
//main program
int main()
{
//Data
string objective =""template for C++ programs and to test code""; //program objective
string instructions =""This will be the user instructions...""; //user instructions
srand(time(0));
int u = rand()%100+1; //random number 1-100
const int guessLimit =100; //number of guesses user can guess
int nGuesses =0; //number of guesses
int guesses[guessLimit]; //guess limit
int uGuess; //user guesses
ofstream fout;
ifstream fin;
string s;
//user introduction
introduction(objective, instructions);
// read line by line from secret.txt file and decode it by substituting each character
fin.open(""score.txt"");
if (!fin.good()) throw ""I/O error"";
cout << u << endl;
cout <<""I'm thinking of a number between 1 and 100. Guess what it is : "" ;
while(true)
{
if (!fin.good()) break;
cin >> uGuess;
if (uGuess <0|| uGuess >100)
{
cout <<""I'm only thinking of a number between 1 and 100: "" ;
continue;
cin >> uGuess;
}
bool b = isRepeatedGuess(uGuess,guesses,nGuesses);
if(b)
{
cout <<""You already guessed ""<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions