Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need helping mainly on reading and writing to a file based on an array or arrays keeping records of first name, last name, and

I need helping mainly on reading and writing to a file based on an array or arrays keeping records of first name, last name, and score. You play a number guessing game which the program generates randomly between 1 and 100 and depending on the number of guesses the user takes, if its higher than the scores before, it stores your name and score to the 'array' in the file and keeps it for the next game. I'm having a lot of trouble making this function to work. Please help.. The following is my code to give you more or less of a view of where I'm stuck on. Thank you. Will rate as well! :)

Part 2

Now implement a high-score record keeping system. The idea is that each time you play (run the program), your name and score should be recorded in a high-score file (at least if you scored in the top ten). At the start of each run, the game should list the top 10 best scores of anyone that has ever played your game.

Here is a sample run:

Welcome to the number guessing game. The top 10 best scores so far are:

Ed Sheeran 4

Camilla Cabello 4

G Easy 5

Robbie Schweller 6

Lil Pump 7

Post Malone 7

Cardi B 9

Dua Lipa 12

Portugal Theman 20

Demi Lovato 53

Think youve got what it takes to make the top ten? Lets find out!

What is your name?

Bebe Rexha

Guess a number between 1 and 100

(etc)

It took you 10 guesses Bebe Rexha!

Not too shabby, but not too good either...

Hey, you made the top 10! Congratulations!

(end program)

The next time the program is run, the following should be displayed. Note that Bebe is now in the top 10, and Demi has been bootedoff.

Welcome to the number guessing game. The top 10 best scores so far are:

Ed Sheeran 4

Camilla Cabello 4

G Easy 5

Robbie Schweller 6

Lil Pump 7

Post Malone 7

Cardi B 9

Bebe Rexha 10

Dua Lipa 12

Portugal Theman 20

/*****************************************IN C++******************************************************************/ //records.h

#ifndef records_h #define records_h using namespace std; class records { private: public: string name; int score; //default constructor records() { name = "Blank"; score = 0; } //parameterized constructor records(string n, int s) { name = n; score = s; } };

*/ /***********************************************************************************************************/ //main.cpp #include #include //#include "records.h" using namespace std;

//should i read or write first? //When is it accurate to file.close(); //should a void function be better? //for loop? #include int main() { cout<<"Welcome to the Guessing Game! The top 10 best scores are:"<> firstName[i]; } for(int j = 10; j < 20; j++) { file >> lastName[j]; }

} for(int i=0;i<10;++i) { cout<< "First Name is: " << firstName[i] << endl;

} for(int j=10;j<20;++j) { cout<< "Last Name is: " << lastName[j] << endl; } /* cout<<"Think youve got what it takes to make the top ten? Lets find out!"<> guessedNumber; num_tries++; if (guessedNumber > randomNumber) { cout << "Too high!! "; } else if (guessedNumber < randomNumber) { cout << "Too low!! "; } else { cout << " You Win!!"<

Ed Sheeran 4 Camilla Cabello 4 G Easy 5 Robbie Schweller 6 Lil Pump 7 Post Malone 7 Cardi B 9 Bebe Rexha 10 Dua Lipa 12 Portugal Theman 20

//Feel free to rearrange the order if easier to sort, I've attempted this method as well but no luck //As in First 10 lines the first name, followed by the last.. thanks again. Shouldn't be too difficult for a fluent programmer in C++

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

Students also viewed these Databases questions