Create organized functions with the single lines of code by declaring the functions, calling the function, then defining the function. Please help me make this look cleaner... The code should operate the same. C++ #include #include #include #include using namespace std; int main() { srand(static_cast (time(0))); const int N = 4; string wordP[N] = { "engineer", "cooper union", "final", "new york university" }; for (int i = 0; i <= N; i++) { cout << wordP[i]<< endl; } label: int z = rand() % N; string word = wordP[z]; string scrambled = word; const int rp = scrambled.size(); for (int letter = 0; letter < rp; letter++) { int z = rand() % rp; char game = scrambled[z]; scrambled[z] = scrambled[letter]; scrambled[letter] = game; } unsigned int t1 = time(0); string begin; do { cout << "Lets play a game.." << endl << " Unscramble the following words in order to proceed" << " " <> begin; if (begin == word) { cout << "Congratulations you beat the game" << endl; break; } } while (begin != "Quit"); unsigned int t2 = time(0); unsigned int score = (t2 - t1); cout << "It took " << score << "seconds" << endl; cout << " Thank you, come again!!" << endl; char approval; cout<<"Do you wish to play again (y for yes, n for no): "; cin>>approval; if(approval == 'y'){      cout<<"\n\n";      goto label; }  else      cout<<"\nExiting...."; return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create organized functions with the single lines of code by declaring the functions, calling the function, then defining the function. Please help me make this look cleaner... The code should operate the same. C++

#include <iostream>
#include <vector>
#include <string>
#include <ctime>
using namespace std;


int main()
{
srand(static_cast<unsigned int> (time(0)));
const int N = 4;
string wordP[N] = { "engineer",
"cooper union", "final", "new york university" };


for (int i = 0; i <= N; i++) {
cout << wordP[i]<< endl;
}

label:

int z = rand() % N;
string word = wordP[z];
string scrambled = word;

const int rp = scrambled.size();

for (int letter = 0; letter < rp; letter++) {

int z = rand() % rp;
char game = scrambled[z];
scrambled[z] = scrambled[letter];
scrambled[letter] = game;
}

unsigned int t1 = time(0);

string begin;
do {
cout << "Lets play a game.." << endl << " Unscramble the following words in order to proceed" << " " <<endl<< "word:"<<" "<<scrambled << endl;
cin >> begin;
if (begin == word) {
cout << "Congratulations you beat the game" << endl;
break;
}

} while (begin != "Quit");
unsigned int t2 = time(0);
unsigned int score = (t2 - t1);
cout << "It took " << score << "seconds" << endl;
cout << " Thank you, come again!!" << endl;
char approval;
cout<<"Do you wish to play again (y for yes, n for no): ";
cin>>approval;
if(approval == 'y'){
     cout<<"\n\n";
     goto label;
}
 else
     cout<<"\nExiting....";
return 0;
}

 

Expert Solution
Step 1

Answer:

I have done code  and also I have attached code and code screenshot as well as output 

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education