Calling Functions Need Response ASAP

I need assistance on calling functions for a program. I have tried various things, but cannot get the correct output.Please assist. I am lost and confused.


#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <cstdlib>
using std::rand;
using std::srand;

#include <ctime>
using std::time;

void multiplication(); // function prototype for the function you are programming!
void correctMessage(); // function prototype
void incorrectMessage(); // function prototype
bool needHelp( int, int ); // function prototype

int main()
{
srand( (unsigned int)time( 0 ) ); // seed random number generator
multiplication(); // begin multiplication practice

return 0; // indicate successful termination

} // end main

// function multiplication produces pairs of random numbers and prompts the user for the product
// it also produces random comments for correct and incorrect answers by calling the appropriate function
// in addition, it counts the number of correct and incorrect answers, and
// after 10 answers, it calculates the percentage of correct answers;
// if the percentage is lower than 75%, it calls the function needHelp and terminates.

void multiplication()
{
// Variable declarations; no other variables are required.
int x; // first factor
int y; // second factor
int response = 0; // user response for product
int correct = 0; // total number of correct responses
int incorrect = 0; // total number of incorrect responses
int count = 0; // count for every 10 responses

// use sentinel-controlled repetition
cout << "Enter -1 to End." << endl;

// loop until sentinel value read from user
while ( response != -1 )
{
x = rand() % 10; // generate 1-digit random number
y = rand() % 10; // generate 1-digit random number

cout << "How much is " << x << " times " << y << " (-1 to End)? ";
cin >> response;

// loop until sentinel value or correct response
while ( response != -1 && response != x * y )
{
response = incorrect; // calls incorrectMessages()
} // end while

// correct response
if ( response == x * y )
response = correct; // call correctMessage()
} // end while

cout << "That's all for now. Bye." << endl;
} // end function multiplication


// function correctMessage randomly chooses response to correct answer
void correctMessage()
{
// generate random number between 0 and 3
switch ( rand() % 4 )
{
case 0:
cout << "Very good!";
break;
case 1:
cout << "Excellent!";
break;
case 2:
cout << "Nice work!";
break;
case 3:
cout << "Keep up the good work!";
break;
} // end switch

cout << endl << endl;
} // end function correctMessage



// function incorrectMessage randomly chooses response to incorrect answer
void incorrectMessage()
{
// generate random number between 0 and 3
switch ( rand() % 4 )
{
case 0:
cout << "No. Please try again.";
break;
case 1:
cout << "Wrong. Try once more.";
break;
case 2:
cout << "Don't give up!";
break;
case 3:
cout << "No. Keep trying.";
break;
} // end switch

cout << endl << "? ";
} // end function incorrectMessage



// function needHelp returns true if < 75% right
bool needHelp( int right, int wrong )
{
// if < 75% right
if ( static_cast< double > ( right ) / ( right + wrong ) < .75 )
{
cout << "Please ask your instructor for extra help." << endl;
return true;
} // end if
else // otherwise, return false
return false;
} // end function needHelp

I see you tried to put code tags, but didn't quite get it.

Anyway you need to be more specific. What output are you getting and what output were you expecting.
how do you get this to keep track of the correct and incorrect responses and end with the needHelp function, etc?
First of all, please put that in code tags, secondly, be more specific about your problem, thirdly, just a hint: instead of using all those "std::thing, std::thing2" just use after your #includes "using namespace std;
kiberstar wrote:
instead of using all those "std::thing, std::thing2" just use after your #includes "using namespace std;

"using namespace std" is considered bad practice as it pollutes the global namespace, and takes away the point of having namespaces. OP uses a better approach as he using using only to the names he will be using. I personally only use using in local scope and only to names which I use very often (usually only cout and endl).
Topic archived. No new replies allowed.