0

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;
}
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jim Larkin
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 }

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.