Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

my code is working but i want to remove all the processes from main and put them into a different function. 

#include <iostream>
#include <iomanip>

using namespace std;

void holdScreen();
void developerInfo();
int askmultiplyQuestion(); 
double isGivenSolutionCorrect(int givenAnswer, int expectedAnswer);
int numberOfCorrectResponses = 0; 
int numberOfResponses = 0; 
double percentageOfCorrectAnswers();

//***************************************************************
//
//  Function:     main
// 
//  Description:  The main function of the program
//
//  Parameters:   None
//
//  Returns:      Zero (0) 
//
//**************************************************************
int main()
{
   // Do not delete this statement
   developerInfo();
   
   while (numberOfResponses < 10) { 

     int expectedAnswer = askmultiplyQuestion(); 
 do { 
        int givenAnswer; 
        cin>> givenAnswer; 
        numberOfResponses += 1; 
        if (isGivenSolutionCorrect(givenAnswer, expectedAnswer)) { 
         numberOfCorrectResponses += 1; 
         break; 
            
        } 
     
    } while (numberOfResponses < 10); 
     
 } 
   
    // Terminate Program
    holdScreen();
    return 0;
}

int askmultiplyQuestion() { 

 int number1 = rand() % 10; 
 int number2 = rand() % 10; 
 
    cout << "How much is " << number1 << " times " << number2 << "? ";
    return number1 * number2; 
     
 }

double isGivenSolutionCorrect(int givenAnswer, int expectedAnswer){


if (givenAnswer == expectedAnswer) {

char const *responses_values[] = { "Very good!", "Excellent!", "Nice work!", "Keep up the good work!" ,"Way to go!"}; 
int numberOfResponses = (sizeof(responses_values) / sizeof(responses_values[0])); 
cout << responses_values[rand() % numberOfResponses] << endl; 
return true; 
}

else { 
char const *responses_values[] = { "That is incorrect!", "No. Please try again!", "Wrong, Try once more!", "No. Don’t give up!" ,"Incorrect. Keep trying!"}; 
int numberOfResponses = (sizeof(responses_values) / sizeof(responses_values[0])); 
cout << responses_values[rand() % numberOfResponses] << endl; 
return false; 
}

double percentageOfCorrectAnswers = double(numberOfCorrectResponses) / double(numberOfResponses);{

if (percentageOfCorrectAnswers < 0.75) 
 { cout << "Please ask your teacher for extra help." << endl; }
 else { cout << "Good Job!!" << endl; }
return 0; 
}
}
//*********************************************************************
//
//  Function:     holdScreen
// 
//  Description:  The hold screen function
//
//  Parameters:   None
//
//  Returns:      N/A 
//
//*********************************************************************
void holdScreen()
{
   char ch;

   cout << "\nPress any key to exit... ";
   ch = getchar();
}

//***************************************************************
//
//  Function:     developerInfo
// 
//  Description:  The developer's information
//
//  Parameters:   None
//
//  Returns:      N/A 
//
//**************************************************************
void developerInfo()
{
    cout << "Name:     Hussain Aldulaimi" << endl;
    cout << "Course:   COSC 1337 Programming Fundamentals II" << endl;
    cout << "Program:  Eight" 
         << endl
         << endl;
} // End of developerInfo

 

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education