I need to write a program that generates 10 problems, in which 2 randomly genorated numbers are chosen to multiply together, and the user has to input the correct answer for each program, and i have store the answers, and check to see if they are correct. I could just use a little help in understanding how to write the array code, and how to recall the stored numbers. I understand it starts storeing with 0 and goes up. Any help would be greatly appreciated

*generate the 10 problems.
*Use the function rand() to generate random digits from 0 through 9.
*I need to use 4 arrays to do this. the first 2 arrays for the numbers multiplyed, and the 3rd for the student answer, and fourth holds correct answers to do check with.

thanks again!

Member Avatar for iamthwee

give us sum code then give us sum quesitons... I'm not gonna do ur homework again for you.

Hey guys this is what i got, and it works, however one aspect i have no idea how to do is to do a check to make sure that the same multiplication problems do get generated twice, so something like 3 * 2 wouldnt have 2*3 or 3*2 show up again... I thought that perhaps doing the factorial of each randomly generated number but i tried it as you can see here and i dont think it works.. any help would be sweet.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <time.h>

//double long Factorial ( int ) ;
using namespace std;



int main()
{
		//DECLARATIONS
int  u[11], r[11], t[11], answer[11], correct[11], value[11];		//aa = answer
int a=0, seed, c; //c is correct answers
int randvalue[11], randvalue2[11] ;

cout<<"please enter a starting number:";
cin>>seed;
srand(seed);
cout<<endl;


c=0;
int p=1;




	for (int i=1; i<=10; i++)	
	{
randvalue[i] = rand() % 10 ;
randvalue2[i] = rand() %10 ;
correct[i] = randvalue[i] * randvalue2[i];
	}
/*value[i] = Factorial (randvalue[i]) + Factorial (randvalue2[i]);
	


u[i] = Factorial (randvalue[i]);
r[i] = Factorial (randvalue2[i]);
t[i] = u[i]+r[i];
cout<<u[i];

while (value[i] = t[i])
{
randvalue[i] = rand() % 10 ;
randvalue2[i] = rand() %10 ;
correct[i] = randvalue[i] * randvalue2[i];
}
	}*/

while (p<=10)
{

cout << "Problem "<<p<<": What is "<<randvalue[p]<<" * "<<randvalue2[p]<<"?:";
cin >> answer[p];
	



if (answer[p] == correct[p])
{	
cout<<"Correct!\n";
	c++;
}
else
{
cout<<"Incorrect\n";
}
p++;
}

cout<< "Your score is "<<c<<"out of 10\n";
cout<<"\nLets Review the ones you missed: \n";
cout<<"\nPROBLEM:     |     YOUR ANSWER:\n";
cout<<"-------------------------------\n";

for (i=0; i<=10; i++)

if (answer[i] != correct[i])
cout <<randvalue[i]<<" * "<<randvalue2[i]<<" = "<<correct[i]<<"               "<<answer[i]<<endl;



return 0;
}

/*double long Factorial ( int  Number )      //  function's heading
{
double long NFACT = 1 ;
	if (Number == 0 )
		return NFACT ;
	else
		NFACT = Number * Factorial(Number - 1 ) ;
	return NFACT ;
}*/
Member Avatar for iamthwee

kisvirag21
however one aspect i have no idea how to do is to do a check to make sure that the same multiplication problems do get generated twice

Are u sure that is even ur part of ur homework kiddo? Check wit ur teacher.

kisvirag21
I thought that perhaps doing the factorial of each randomly generated number

Er...that wont work.

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.