hi guys i need ur help to do my homework
i have this question
Write a program that helps students to learn multiplication.
Use rand to produce two positive one-digit integer. It should then type a question such as How much is 6 times 7?
The student type the answer. Your program check the answer if it correct print "very good" then ask another multiplication question. If the answer is wrong print "NO, try again" then let the student try the same question again until the student gets the right answer.

my problem that i don't know how to multiply to random numbers
look to what i did

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

#include <cstdlib>
using std::rand;

int main()
{
	int number;
	cout << "how much is " << (0 + rand()%10) << " times " << (0 + rand()%10) << "?";
	cin >> number;
	if (number == (0 + rand()%10)*(0 + rand()%10)== (0 + rand()%10)*(0 + rand()%10))
	{
		cout <<"very good";
	}
	else
	{

	}
	cout << endl;

	return 0;
}

please help me with this question
thanks

Save the results of the rand() calls in separate variables.

num1 = rand();
num2 = rand();
if ( guess == num1 * num2 )

thank u so much salem
look to waht i did now

int main()
{
    int number1 = 1 + rand()%10;
    int number2 = 1 + rand()%10;
    int multi = number1 * number2;
    cout << "how much is " << number1 << " times " << number2 << "?";
    cin >> multi;
    if ( multi == number1 * number2)
    {
        cout <<"very good";
    }
    cout << endl;

    return 0;
}

i didn't complete it yet
i have to work with else too
but my problem now
is how can i let the program ask the question again if the answer is wrong????
and change the question after the student get the right answer.
thanks again salem
u r the best

hi again
i need to know how can i change the random number every time i run the program
they are always the same
thanks

You need to seed rand. srand (time(0)) ( it uses ctime I think so include that)

To keep getting responses until a correct answer is given,

cin >> multi;
while ( multi != number1 * number2)
{
cout <<"That's not it, try again'" << endl;
cout << "how much is " << number1 << " times " << number2 << "?";
cin >> multi;
}

To get a new set of numbers for another drill, you need to wrap your code in a while or do...while loop. After successfully answering the problem, ask the user if they want to do another, get a respones (y or n, for example) and let the loop continue if a positive response is given.

Val

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.