I'm doing an assignment for C++. I'm to write a program that will help elementary school students learn multiplication. Use rand() to produce two integers between +10 and -10 inclusive. The program should then use those numbers to output the question. So far I haven't put the functions in, i'm still confused about that part. My question is my second number isn't being randomized. I'm not sure what i'm doing wrong. Could someone look over my code please?

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
	const int SIZE = 1;
	int list[SIZE];
	int  i, x, answer, guess;
    int counter;
	srand(time(0));

    
	for (i = 0 ; i < SIZE ; i++)
	{
		list[i] = -10 + rand()%10;

	
	for (x = 0; x < SIZE; x++)
	{
        list[x] = -10 + rand()%10;
        }
    
    answer = list[i]*list[x];
    
    cout << "How much is "<< list[i] << " times " << list[x] << "?  ";
    cin >> guess;
    counter = 0;
    
    while (guess != answer)
    {     
          counter++;
          cout << "Your answer is wrong, try again.";
          cout <<endl;
          cin >> guess;          
    }
    if (guess == answer)
          {
           counter++;
           cout << "Very Good!" <<endl;
          }
          cout << "It took you " << counter << " tries.";
}
    getch();
	return 0;
}

I'm guessing that right here:

for (i = 0 ; i < SIZE ; i++)
{
list = -10 + rand()%10;

you didn't close your for loop with }

be careful with braces

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.