mardi 31 octobre 2017

I want to generate some mathematical questions by using rand and function

I am learning c++ program in my home. So I am not good at using it.

  1. First I want to output the programme like the below statement.
  2. "Question 1: 4 + 5 = 9 correct!
  3. "Question 2: 5 * 5 = 9 fail!
  4. "Question 3: 9 - 5 = 4 correct! I want to produce the question at least 5 and not more than 10 questions. My curiosity is that how can I increase the question number and how can I check that whether I answer this question correct or not. This is so far I'm done. Please do understand my code because I am learning C++ alone in my home

int main()
{
int a, b, digit1, digit2,;
char op, k;
a = digit1;
b = digit2;
op = k;

srand (time (NULL));

generate2Digits(a,b);
generateOperators(op);


}

void generate2Digits (int& a, int& b) 
{
    int digit1;
    int digit2;

    srand (time (NULL));

    digit1= rand ()%10;
    digit2= rand ()%10;

    for(int i = 1; i<= rand()%10; i++) 
    {
        cout << digit1 << endl;
        cout << digit2<< endl;
    }


}

void generateOperators(char& op)

{ int k;

    for(int i=1; i<= 10; i++)
    {
        k = rand () % 4;

        switch(k)
        {
            case 0: cout << "+" << endl;
                break;
            case 1: cout << "-" << endl;
                break;
            case 2: cout << "*" << endl;
                break;
    }

}


}

void printExpression(int a, int b, char op)
{
    do
    {






}

// how to print the question expression like the above example? // how to check the whether the answer is correct or not?




Aucun commentaire:

Enregistrer un commentaire