regeneration of already generated randoms?

Hi and thanks as always!

Is there a way to make the numbers regenerate randomly instead of repeating themselves after their first generation, other than "rand()"? I need to make it 1 through 10.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  #include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int ans1, ans2, choice, corr, incorr;
	int	num1, num2, num3, num4;
	int	adcnt = 0, subcnt = 0, multcnt = 0;
	

    cout << "Hello, This program will help you learn addition, subtraction and multiplication! \n";
	cout << "please select one of the options from the menu to start: \n";

    cout << "1. Addition \n";
	cout << "2. Subtraction \n";
	cout << "3. multiplication \n";
	cout << '\n';
	cin  >> choice;

		srand(time(NULL));
		num1 = rand() % 10 + 1;
		num2 = rand() % 10 + 1;
		num3 = rand() % 10 + 1;
		num4 = rand() % 10 + 1;

		switch(choice)
	{
        case 1: adcnt++; 
			cout << '\n';
			cout << "Please add " << num1 << " and " << num2 << '\n';
			cin  >> ans1;
			
			do
			{
			 if (ans1 != num1 + num2)
				{
			     cout << "No. Please try again. \n";
				 cout << "Please add " << num1 << " and " << num2 << '\n';
				 cin >> ans1;
			    }
			     if (ans1 = num1 + num2, ans1 = num3 + num4)
			     {
				 cout << "Very GOOD! \n";
				 cout << "Please add " << num3 << " and " << num4 << '\n';
				 cin >> ans1;
				 }
			 
			}while (ans1 != -1);
The first thing I would do is move the random seed to the first line in main() and write it this way: srand(static_cast<unsigned int>(time(0)));. Second, generate the numbers inside the switch.
Topic archived. No new replies allowed.