1. Let's make the game more playable! Currently, the player wins every other round and each game consists of a single turn. We want to change this! Create a new global variable named computerHealth and initialize it to 100. Inside the loop that represents a single game being played, place another loop. This loop will represent a single round of a game. In each iteration of the inner loop: • The computer will attack the player for a value between 0 and 50. • The player will choose an action (heal, block, special, or regular) • Make the calculated adjustments to computerHealth and playerHealth · If the player health goes below 0, count it as a player loss and break out of the inner loop. • If the computer health goes below 0, count it as a player win and break out of the inner loop. · Otherwise, the inner loop will iterate again (i.e. the computer will attack and the player will pick another action). • You can remove the previous logic of determining a winner based on if it's an even or odd round. 2. Update the block function to "return" two values. It should have one value parameter (computerDamage from before) and two reference parameters (named blockAmount and hitAmount). The function should calculate how much of the attack the user blocks. To do this, select a random number between O and computerDamage and assign it to blockAmount. After determining how much of computerDamage is blocked, assign the rest to hitAmount. In main, print the value of each (we will have access to both since the arguments will be passed by reference). 3. Update your program so that when the user decides to quit, it saves the number of wins and losses to a file. When the program starts, load the data (if it exists). When the program ends, overwrite the previous data with the updated data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ Question:

Hello based on the attached code picture, please update that code so it can follow the instructions given in the other picture. Thank you. 

1. Let's make the game more playable! Currently, the player wins every other round and each game consists of a single
turn. We want to change this! Create a new global variable named computerHealth and initialize it to 100. Inside the
loop that represents a single game being played, place another loop. This loop will represent a single round of a
game. In each iteration of the inner loop:
• The computer will attack the player for a value between O and 50.
• The player will choose an action (heal, block, special, or regular)
Make the calculated adjustments to computerHealth and playerHealth
· If the player health goes below 0, count it as a player loss and break out of the inner loop.
If the computer health goes below 0, count it as a player win and break out of the inner loop.
· Otherwise, the inner loop will iterate again (i.e. the computer will attack and the player will pick another
action).
• You can remove the previous logic of determining a winner based on if it's an even or odd round.
2. Update the block function to "return" two values. It should have one value parameter (computerDamage from
before) and two reference parameters (named blockAmount and hitAmount). The function should calculate how
much of the attack the user blocks. To do this, select a random number between 0 and computerDamage and assign
it to blockAmount. After determining how much of computerDamage is blocked, assign the rest to hitAmount. In
main, print the value of each (we will have access to both since the arguments will be passed by reference).
3. Update your program so that when the user decides to quit, it saves the number of wins and losses to a file. When
the program starts, load the data (if it exists). When the program ends, overwrite the previous data with the updated
data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.
Transcribed Image Text:1. Let's make the game more playable! Currently, the player wins every other round and each game consists of a single turn. We want to change this! Create a new global variable named computerHealth and initialize it to 100. Inside the loop that represents a single game being played, place another loop. This loop will represent a single round of a game. In each iteration of the inner loop: • The computer will attack the player for a value between O and 50. • The player will choose an action (heal, block, special, or regular) Make the calculated adjustments to computerHealth and playerHealth · If the player health goes below 0, count it as a player loss and break out of the inner loop. If the computer health goes below 0, count it as a player win and break out of the inner loop. · Otherwise, the inner loop will iterate again (i.e. the computer will attack and the player will pick another action). • You can remove the previous logic of determining a winner based on if it's an even or odd round. 2. Update the block function to "return" two values. It should have one value parameter (computerDamage from before) and two reference parameters (named blockAmount and hitAmount). The function should calculate how much of the attack the user blocks. To do this, select a random number between 0 and computerDamage and assign it to blockAmount. After determining how much of computerDamage is blocked, assign the rest to hitAmount. In main, print the value of each (we will have access to both since the arguments will be passed by reference). 3. Update your program so that when the user decides to quit, it saves the number of wins and losses to a file. When the program starts, load the data (if it exists). When the program ends, overwrite the previous data with the updated data. You can simply put the number of wins in the first line of the file and the number of losses in the second line.
using namespace std;
void lookupEmployee();
void addEmployee();
int main()
{
int option;
while (true)
{
// Continually give the user three choices
cout « "Enter 1) to lookup an employee, 2) to add an employee, 3) to quit: ";
cin >> option;
if (option == 1)
{
lookupEmployee();
}
else if (option == 2)
{
addemployee();
else if (option == 3)
{
// Quit the program
break;
else
{
cout <« "Invalid option!" « endl;
}
void addEmployee()
{
// Retrieve new employee info from user
int id;
string first, last;
cout <« "Enter the new employee's ID: ";
cin >> id;
cout <« "Enter the new employee's first name: ";
cin >> first;
cout <« "Enter the new employee's last name: ";
cin >> last;
// Open a file for appending
ofstream outFile;
outFile.open("employees.txt", ios::app);
outFile <« id <« " " <« first « "" <« last <« endl;
outFile.close();
}
void lookupEmployee()
// Open the file for reading
ifstream inputFile;
inputFile.open("employees.txt");
if (inputFile.fail())
{
// If the file doesn't exist, exit the function
cout « "File not found!" « endl;
return;
}
// Retrieve the employee id from the user
int idNum;
cout « "Enter the employee'S ID: ";
cin >> idNum;
// Read the file one line at a time (there are three pieces of info on each line)
int id;
string first, last;
while (inputFile >> id)
{
inputFile >> first >> last;
if (id == idNum)
{
// we found the employee the user is looking for
cout <« first « "" « last « endl;
inputFile.close();
return;
}
cout <« "Employee not found!" <« endl;
inputFile.close();
Transcribed Image Text:using namespace std; void lookupEmployee(); void addEmployee(); int main() { int option; while (true) { // Continually give the user three choices cout « "Enter 1) to lookup an employee, 2) to add an employee, 3) to quit: "; cin >> option; if (option == 1) { lookupEmployee(); } else if (option == 2) { addemployee(); else if (option == 3) { // Quit the program break; else { cout <« "Invalid option!" « endl; } void addEmployee() { // Retrieve new employee info from user int id; string first, last; cout <« "Enter the new employee's ID: "; cin >> id; cout <« "Enter the new employee's first name: "; cin >> first; cout <« "Enter the new employee's last name: "; cin >> last; // Open a file for appending ofstream outFile; outFile.open("employees.txt", ios::app); outFile <« id <« " " <« first « "" <« last <« endl; outFile.close(); } void lookupEmployee() // Open the file for reading ifstream inputFile; inputFile.open("employees.txt"); if (inputFile.fail()) { // If the file doesn't exist, exit the function cout « "File not found!" « endl; return; } // Retrieve the employee id from the user int idNum; cout « "Enter the employee'S ID: "; cin >> idNum; // Read the file one line at a time (there are three pieces of info on each line) int id; string first, last; while (inputFile >> id) { inputFile >> first >> last; if (id == idNum) { // we found the employee the user is looking for cout <« first « "" « last « endl; inputFile.close(); return; } cout <« "Employee not found!" <« endl; inputFile.close();
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY