Thread: adding random numbers and giving a correct or incorrect response back to the user

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    3

    adding random numbers and giving a correct or incorrect response back to the user

    /* Mike Shain
    CIS 10 A
    ONLINE
    Project 1

    This program is a Math Tutor program that will ouput different
    random numbers using addition, multiplication, and subtraction.
    It will also tell the user if the answer is correct and the
    print out a report informing the user of how many incorrect and
    correct answers they got.

    ****************** THIS LINE IS 70 CHARACTERS LONG **********
    */
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    using namespace std;

    void doOneSet('+','-','*');
    void RandomNum(int &FirstNum,int &SecondNum);
    //void getNumbers(int &FirstNum,int &SecondNum);
    //void getProbPerSet();


    int main()
    {
    srand(time(0)); //creats random numbers
    //getProbPerSet(); //get amount of problems per set
    doOneSet('+'); //The Addition set
    //doOneSet('-'); //The Subtraction set
    //doOneSet('*'); //The Multiplication set
    //printReports(); //Print the amount incorrect/correct

    //return 0;
    }

    void doOneSet('+','-','*')
    {
    //printHeader
    //getMaxNum
    //doOneProblem

    int FirstNum;
    int SecondNum;
    int Answer; //Answer to problems
    int pCount = 0; //counter for problems sets
    char operand;

    while (pCount < 5)
    {
    RandomNum(FirstNum,SecondNum);

    //this is to check for a leading zero
    //if (FirstNum < 10 || SecondNum < 10)
    //{
    cout << FirstNum << " + "
    << SecondNum
    << " = ";
    cin >> Answer;
    //}
    //else
    //{
    // cout << FirstNum
    // << " + " << SecondNum
    // << " = ";
    // cin >> Answer;
    //}

    pCount ++; //Counts the loop until count = 5

    getNumbers(char operand); //calls the getNumbers function
    //then gets the operator
    }
    }



    ///*this will be renamed getOperand()
    void getNumbers(char &operand)
    {
    //char operand;
    switch (operand)
    {
    case '+' :
    {
    //Addition
    operand = FirstNum + SecondNum;
    break;
    }
    case '-' :
    {
    //Subtraction
    operand = FirstNum - SecondNum;
    break;
    }
    case '*' :
    {
    //Multiply
    operand = FirstNum * SecondNum;
    }
    }
    }
    */
    void RandomNum(int &FirstNum, int &SecondNum)
    {
    for (int i = 0 ; i < 100; i++)
    {
    //cout << setw(8) << rand() % 101;
    FirstNum = rand() % 101;
    SecondNum = rand() % 101;

    if (i % 5 == 4)
    {
    //cout << endl;
    }
    }
    }

    void getProbPerSet()
    {

    }

  2. #2
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    If you want someone to at least try and answer your question, better use tags and to write neat code. That way people can at least read it from the beginning till the end
    what does signature stand for?

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    void doOneSet('+','-','*');

    huh ? If this is the declaration, use types as parameters, not constants.

    Other than that... what exactly do you need help with ?
    Nice program, but your question is what ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    3
    what the program is supposed to do is call the doOneSet() function 3 times and print out a set of problems based off of the operator (+,-,*).

    So basically the first call would print out 5 addition problems and the 6 subtraction problems etc...

    After all that is done as the user does each problem it shows them either correct or incorrect.

Popular pages Recent additions subscribe to a feed