Random Number Generator Error

The following is my code, I have the GetProduct function down, I believe I possibly have the printEvenAscending function down but if not i'm open to help (My goal was to have the user input two numbers and have the program print out only the even numbers in Ascending order). My error lies within my print5Rand function, my focus was to make a random number generator between the numbers 3 and 88 but when trying to compile and run I reach errors. As you might be able to tell i'm still a beginner at coding, whatever advice or info you have I am more than willing to listen, thank you!

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
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

void GetProduct ( int A, int B, int & Product );
int printEvenAscending ( int num1, int num2);
int print5Rand (int number3, int number88, int output);

int main()
{
	int First, Second, PROD;
	
	cout << "Input two integers";
	cin >> First >> Second;
	
	GetProduct( First, Second, PROD );
	
	cout << PROD << endl;
	
	system("pause");
	return 0;
}

void GetProduct ( int A, int B, int & Product )
{
	Product = A * B;
	
	return;
}

int printEvenAscending (int num1, int num2)
{
	cout << "Input two numbers";
	cin >> num1 >> num2;

    int i;

    for(i = num1; i < num2; i++)
	{

      if(i % 2 == 0) 
	  {
         cout << i <<" "; 
      }
   	}
    return 0;
}

int print5Rand (int number3, int number88, int output)
{
    int number3, number88, output;

    number3 = 3;
    number88 = 88;

    srand(time(NULL));

    for (int i = 0; i < 5; i++) {
    output = rand()%((number3 - number88) + 1); 
    cout << output << "  ";
    
    return 0;
}
srand() goes in main(). But, since this is C++, you might as well do it right.

1
2
#include <chrono>
#include <random> 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// This here function generates a random integer in the range min..max, inclusive.
int random_in_range( int min, int max )
{
  thread_local std::ranlux48 rng( std::chrono::system_clock::now().time_since_epoch().count() );
  return std::uniform_int_distribution <int> ( min, max )( rng );
}

int main()
{
  ...
}

// Prints 5 random numbers in the range 3..88 inclusive, separated by commas.
void print5Rand()
{
  for (int i = 0; i < 5; i++)
  {
    std::cout 
      << (i == 0 ? "" : ", ")
      << random_in_range( 3, 88 );
  }
  std::cout << "\n";
}

Please be more careful about your indentation and brace usage. What you are doing now will hurt you.

Hope this helps.
Topic archived. No new replies allowed.