I am trying to building this program to run 10 times and then calculate at the end with needHelp if 75% or more was correct or incorrect. For each random number multiplication question correct and incorrect messages come up. I have been working on this for 3 days and it is due today. Can anyone help me get over this hump and get the looping to work and the needhelp call to work?

This is what I have:

#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 I am programming!
void correctMessage(); // function prototype
void incorrectMessage(); // function prototype
bool needHelp(int, int); // function prototype

int main() // start of main
{
    srand( 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

    // pick random number from 1 to 9
        x = 1 + rand() % 9; // first random number 
        y = 1 + rand() % 9; // second random number

    for (count = 1; count <= 10; count++);
        // Ask the question and get the response
    {
        cout << "How much is " << x << " times " << y << " (-1 to End)? ";
    }   
        cin >> response;
                count++;

// calculate the value of the two random numbers    
             while (count != 10 )
    {   
             if
            ( response == x * y ){ // response is correct
            return correctMessage (); 
            ( correctMessage ); ++correct;
            }
            else
            {
            return incorrectMessage (); 
                ( incorrectMessage ); ++incorrect; 
        cout << endl << endl;
             }

             if ( count = 10 )
             {
            cout << needHelp;
             }

    } // end while          

    cout << "That's all for now. Bye" << endl;

} // end funtion multiplication

    // function correctMessage randomly chooses response to correct answer
    void correctMessage()

    {
        // generate random number between 0 and 3
        switch ( rand() % 3 )
        {
        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;

    }

    // function incorrectMessage randomly chooses response to incorrect answer
    void incorrectMessage()
    {
        // generate random number betwen 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 << "Dont 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 correct, int incorrect)
    {
        // if <75% right
        if(static_cast<double>(correct) / (correct + incorrect) < .75)
        {
            cout << "Please ask your instructor for extra help." << endl;
            return true;
        } // end if
        return false;
    } // end function needHelp

By "run" do you mean re-start the program, or loop through the program multiple times?

By "run" do you mean re-start the program, or loop through the program multiple times?

I want to loop through the program 10 times then call the needhelp function at the bottom to get the results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.