Question: C++ PROGRAMMING How do I add a high score file that contains only one name and one score and then compare the user's score to

C++ PROGRAMMING

How do I add a high score file that contains only one name and one score and then compare the user's score to the high score and replace if the user's score was greater?

HERE IS THE ASSIGNMENT AND CURRENT CODE:

C++ PROGRAMMING How do I add a high score file that contains

/*rpgv3.cpp

This program is a version 3 of the RPG. */

#include #include #include #include #include using namespace std;

//Define the main function int main() { //Declare and initialize variables int menuChoice = 0, doorChoice = 0, weaponChoice = 0, score1 = 0, score2 = 0, totalScore = 0, myRandom = 0; string player, date;

//Introduction cout

while (menuChoice != 3) { //Display Main menu cout

//Prompt the user for a choice from the main menu cout > menuChoice;

//decision structure to determine the program path //multi-way if statement if (menuChoice == 1) { //Display the rules cout

else if (menuChoice == 2) { //Play the game //Prompt the user for player's name cout > player;

//Prompt the user for the date (define date format) cout > date;

cout

//Intro to Menu Option 2 cout

cout

//Display door selection menu cout

//prompt for doorChoice cout > doorChoice;

//decision structure to determine the program path based on doorChoice //multi-way if statement if (doorChoice == 1) { //Display winning door choice cout

//display formatted chart for the player's name, score, and the date for door 1 //set columns to a width of 15 characters each cout

}

else if (doorChoice == 2) { //Display action door and weaponChoice menu cout

score1 = 500;

//prompt the user for weaponChoice cout > weaponChoice;

//decision structure to determine the program path based on weaponChoice //multi-way if statement if (weaponChoice == 1) { cout

//display formatted chart for the player's name, score, and the date for door 2/weapon 1 //set columns to a width of 15 characters each cout

}

else if (weaponChoice == 2) { cout

//display formatted chart for the player's name, score, and the date for door 2/weapon 2 //set columns to a width of 15 characters each cout

} else if (weaponChoice == 3) { cout

//display formatted chart for the player's name, score, and the date for door 2 / weapon 3 //set columns to a width of 15 characters each cout

} else { cout

//display formatted chart for the player's name, score, and the date for wrong door //set columns to a width of 15 characters each cout

//display formatted chart for the player's name, score, and the date for Door 3 //set columns to a width of 15 characters each cout

} else if (menuChoice == 3) { //Exit cout

//declare a file pointer for output ofstream outfile;

//open file "highscore.txt" for appending outfile.open("highscore.txt", ios::app);

outfile

//close file outfile.close();

}

return 0; }

(25 pts) Add a high score file to your game. Create a text file called "highscore.txt" that contains the following text: first Name When the user has completed the game o Read in and store the current high score and name in the file o Compare your user's score to the current high score. o If the user's score is greater than the current high score replace the name and score in the text file with the user' s name and score (25 pts) Add a high score file to your game. Create a text file called "highscore.txt" that contains the following text: first Name When the user has completed the game o Read in and store the current high score and name in the file o Compare your user's score to the current high score. o If the user's score is greater than the current high score replace the name and score in the text file with the user' s name and score

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!