Correct logic error and modify the  C++ code. 1-Use loop 3 times to ask pin from user when user enter wrong pin 3 times then excute the program. 2-if user correct guess before tries excute and ask if you play again if user say no excute the program. 3-Correct line Geneerate random number between 1 to 50. 4-Correct logic error if you found anyothers.   Code:   //included header file for basic input output stream #include //included header file for file stream #include //included header file to use rand() function #include //included header file to use time() function #include //included namespace using namespace std; //function to generate random number int generateRandom() { //use srand() function to change the random number after each execution srand((unsigned int) time(0)); //generated a random number between 1-50 through rand() function int randomNumber = rand()%50; //return random number to main() return randomNumber; } //function tooLow() void tooLow() { //print statement to print the message cout << "You have guessed too low." << endl; } //function tooHigh() void tooHigh() { //print statement to print the message cout << "You have guessed too high." << endl; } //function guessedCorrect() void guessedCorrect() { //print statement to print the message cout << "You have guessed correct." << endl; } //function to check guess void checkGuess(int guess, int randomNumber) { //If the users guesses below the number if (guess < randomNumber) //call a function tooLow() tooLow(); //If they guess over that number elseif (guess > randomNumber) //call a function tooHigh() tooHigh(); //else statement else //call a function guessedCorrect() guessedCorrect(); } //function to start game void guessGame() { //welcome message cout << "------------Welcome to the game------------" << endl; //variable declaration int guess, level, trial = 0, numberOfTries; cout << "Enter level of game: " << endl; cout << "Press 1 for easy level" << endl; cout << "Press 2 for medium level" << endl; cout << "Press 3 for hard level" << endl; //input level cin >> level; //switch level switch (level) { //case 1 case1: //assign numberOfTries to 8 numberOfTries = 8; //break break; //case 2 case2: //assign numberOfTries to 5 numberOfTries = 5; //break break; //case 3 case3: //assign numberOfTries to 2 numberOfTries = 2; //break break; //default case default: //display message "Wrong choice entered." cout << "Wrong choice entered." << endl; } //while loop run until numberOfTries while (trial < numberOfTries) { cout << "Enter your guess: "; //input number from user cin >> guess; //calling generateRandom int randomNumber = generateRandom(); //calling checkGuess() checkGuess(guess, randomNumber); //increment trial trial++; } } //main function int main() { //declared variable guess int pin, filePin; //created file ifstream file; //opening file file.open("gamePin.txt"); //input pin from user cout << "Enter pin: "; cin >> pin; //extract pin from file file >> filePin; //compare user pin and pin in file if (pin == filePin) //calling guessGame() guessGame(); //else statement else //display message "Wrong pin" cout << "Wrong pin" << endl; return0; }

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
 
Correct logic error and modify the  C++ code.
1-Use loop 3 times to ask pin from user when user enter wrong pin 3 times then excute the program.
2-if user correct guess before tries excute and ask if you play again if user say no excute the program.
3-Correct line Geneerate random number between 1 to 50.
4-Correct logic error if you found anyothers.
 
Code:
 
//included header file for basic input output stream
#include<iostream>
//included header file for file stream
#include<fstream>
//included header file to use rand() function
#include<cstdlib>
//included header file to use time() function
#include<ctime>
//included namespace
using namespace std;
//function to generate random number
int generateRandom() {
//use srand() function to change the random number after each execution
srand((unsigned int) time(0));
//generated a random number between 1-50 through rand() function
int randomNumber = rand()%50;
//return random number to main()
return randomNumber;
}
//function tooLow()
void tooLow() {
//print statement to print the message
cout << "You have guessed too low." << endl;
}
//function tooHigh()
void tooHigh() {
//print statement to print the message
cout << "You have guessed too high." << endl;
}
//function guessedCorrect()
void guessedCorrect() {
//print statement to print the message
cout << "You have guessed correct." << endl;
}
//function to check guess
void checkGuess(int guess, int randomNumber) {
//If the users guesses below the number
if (guess < randomNumber)
//call a function tooLow()
tooLow();
//If they guess over that number
elseif (guess > randomNumber)
//call a function tooHigh()
tooHigh();
//else statement
else
//call a function guessedCorrect()
guessedCorrect();
}
//function to start game
void guessGame() {
//welcome message
cout << "------------Welcome to the game------------" << endl;
//variable declaration
int guess, level, trial = 0, numberOfTries;
cout << "Enter level of game: " << endl;
cout << "Press 1 for easy level" << endl;
cout << "Press 2 for medium level" << endl;
cout << "Press 3 for hard level" << endl;
//input level
cin >> level;
//switch level
switch (level) {
//case 1
case1:
//assign numberOfTries to 8
numberOfTries = 8;
//break
break;
//case 2
case2:
//assign numberOfTries to 5
numberOfTries = 5;
//break
break;
//case 3
case3:
//assign numberOfTries to 2
numberOfTries = 2;
//break
break;
//default case
default:
//display message "Wrong choice entered."
cout << "Wrong choice entered." << endl;
}
//while loop run until numberOfTries
while (trial < numberOfTries) {
cout << "Enter your guess: ";
//input number from user
cin >> guess;
//calling generateRandom
int randomNumber = generateRandom();
//calling checkGuess()
checkGuess(guess, randomNumber);
//increment trial
trial++;
}
}
//main function
int main() {
//declared variable guess
int pin, filePin;
//created file
ifstream file;
//opening file
file.open("gamePin.txt");
//input pin from user
cout << "Enter pin: ";
cin >> pin;
//extract pin from file
file >> filePin;
//compare user pin and pin in file
if (pin == filePin)
//calling guessGame()
guessGame();
//else statement
else
//display message "Wrong pin"
cout << "Wrong pin" << endl;
return0;
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
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