Multiplication

Pages: 12
Thanks long, I do need to use a separate function outside of main... would your route eliminate the separate function?
That still keeps a separate function outside of main to generate a random number.
can you post the longer code, I'm not seeing how this works with the outside function
The separate function no longer takes a parameter, so the function prototype updates to:

int numbergen(); //initializes number generator function less than 9

Two lines are added to the beginning of the while loop, and the call to the numbergen function is removed from the printf line.

1
2
3
4
5
6
7
while ( userAnswer != -1 )
	{ //start while loop for quiz
		number1=numbergen(); // assign random number to number1
		number2=numbergen(); // assign random number to number2
		printf("\nWhat is %d multiplied by %d?\n",number1, number2);
		scanf( "%d", &userAnswer );
		answer=number1*number2;


Separate function is just this.
1
2
3
4
int numbergen()
{
	return 1+(rand()%9); //generates a random number 1-9
}//end number generator  
Last edited on
Topic archived. No new replies allowed.
Pages: 12