Need help with this program assignment

So at this point I am lost.
My teacher wants us to generate an array that contains random positive integers that will allow the user to do different things with those integers. such as REVERSE, ADD, SEARCH and EXIT the program, which then returns the user back to the beginning to start over.

To reverse the array,
I tried finding tutorials and solutions on how to reverse an array but it confused me more when it came to how to use it in my program. so the compiler is currently giving me the following errors:

line 23 col 28 [Error] request for member 'length' in 'normalArray', which is of non-class type 'int'
line 47 col 50 [Error] invalid types 'int[int]' for array subscript

Here is the code I have so far:

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 <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int normalArray;
	void linearSearch( const int [], int, int );
	char option; //declaring options R, A, S, E the users will select 
    
    int length=normalArray.length();
     int reverseArray[length];
    
    
    
cout << "-------------------------------------------------------" << endl;
srand(time(0));
int search, array[10]; // 
for ( int x = 0; x < 10; x++ ) // 
	{
	cout << setw(3) << ( rand() % (100 - 60 +1) + 60);// Prints out 9 random numbers between 60 and 100
	int srand[10] = {rand() % 40 + 61}; //puts a number into array
	}

cout << "\n R[everse]      A[dd]     S[earch]      E[xit]";

cout << "\n Choose what to do with the random array of numbers: ";
cin >> option;

if(option == 'R'|| option =='r')
{
    
	 for(int count=0; count<10; count++)
	    { 
	        reverseArray[count]=normalArray[length-1];
	        length--;
	    }
	cout << "The reverse version of the array = " << reverseArray << endl;
}

/*--------------------------------------------------------------*/
else if (option == 'A' || option == 'a')
cout<< "The sum = " << endl;


/*---------------------------------------------------------------*/
else if (option == 'S' || option == 's')
	{
		cout << "Please enter a number to search for "<< endl;
		cin >> search;
		cout << "The value of that element is: " << search << endl;
	}
/*--------------------------------------------------------------------*/

while (option !='E' && option != 'e');
cout << "End of program";

return 0; //indicates a successful termination

} // end main 
To give you a quick idea on how to randomize and generate an array:

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
#include <iostream>
#include <random>

void initializeArrayRandomly(int num[], int size);
int randomChoice(int min, int max);

int main()
{
    const int ELEMENTS{ 10 };
    int numbers[ELEMENTS] = { 0 };

    initializeArrayRandomly(numbers, ELEMENTS);
}


void initializeArrayRandomly(int num[], int size)
{
    std::cout << "Entering the following integer numbers (randomly):\n";
    for (int count = 0; count < size; count++)
    {
	   std::cout << "Row # " << count + 1 << " : ";
	   num[count] = randomChoice(60, 100); // Call the random function and set the min, max values to generate random numbers.
	   std::cout << num[count] << std::endl; // Display the array with random numbers.
    }
}

// Set up the random number Generator (C++ 11).
int randomChoice(int min, int max)
{
    std::mt19937 generator(std::random_device{}());
    std::uniform_int_distribution<int> distributionToss(min, max); // Set the numbers for int.
    const int randNumber = distributionToss(generator);

    return randNumber;
}


It should look something like this:
https://www.youtube.com/watch?v=U4BOYd5bCZ0
@chicofeo

the compiler is giving me the following errors:

line 25: invalid conversion from 'int' to 'int*' [-fpermissive]
line 17: [note] initializing argument 1 of 'void intializeArrayRandomly(int*, int)'
line 88: mt19937 is not a member of 'std'
line 88: random_device is not a member of std
line 89: uniform_int_distribution is not a member of std
line 89: expected primary-expression before int
line 90: generator was not declared in this scope
line 90: distributionToss cannot be used as a function

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

/*
Kaylah Hubbard
April 26, 2016
ELET 2300 - Assignment 2
Program description: This is a program that generates
an array filled up with random positive integer number ranging
from 60 to 100, and displays it on the screen.
*/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

void intializeArrayRandomly(int numbers[], int size); //
int randomChoice(int min, int max); //

int main()
{
	int numbers;
	const int ELEMENTS{ 10 };
	int number[ELEMENTS] = { 0 };
	intializeArrayRandomly(numbers, ELEMENTS);
	
	void linearSearch( const int [], int, int );
	char option; //declaring options R, A, S, E the users will select 
    
cout << "-------------------------------------------------------" << endl;
srand(time(0));
int search, array[10]; // 
int x;
for ( int x = 0; x < 10; x++ ) // 
	{
	cout << setw(3) << ( rand() % (100 - 60 +1) + 60);// Prints out 9 random numbers between 60 and 100
	int srand[10] = {rand() % 40 + 61}; //puts a number into array
	}

cout << "\n R[everse]      A[dd]     S[earch]      E[xit]";

cout << "\n Choose what to do with the random array of numbers: ";
cin >> option;

if(option == 'R'|| option =='r')
{
   
	 for(int count=0; count<10; count++)
	    { 
	 
	    }
	cout << "The reverse version of the array = " << endl;
}

//*************************************************************************************
else if (option == 'A' || option == 'a')

cout<< "The sum = " << endl;


//*************************************************************************************
else if (option == 'S' || option == 's')
	{
		cout << "Please enter a number to search for "<< endl;
		cin >> search;
		cout << "The value of that element is: " << search << endl;
	}
//*************************************************************************************

while (option !='E' && option != 'e'); // Should be (option !='E' && option != 'e')
cout << "End of program";

return 0; //indicates a successful termination

} // end main 

void intializeArrayRandomly (int num[], int size)
{
	int count;
	cout << "Row # " << count + 1 << " : ";
	num[count] = randomChoice(60, 100); //random function called
	cout << num[count] << endl; //display of random numbers
}

int randomChoice(int min, int max) 
{
	int distributionToss;
	std::mt19937 generator(std::random_device{}());
	std::uniform_int_distribution<int> distributionToss(min, max); //sets numbers for int
	const int randNumber = distributionToss(generator);
	
	return randNumber;
}
Perhaps I should have copy and pasted the assignment instructions

---------------------- assignment instructions -----------------------------------------------------

Write a program that generates an array filled up with random positive integer number
ranging from 60 to 100, and display it on the screen.

After the creation and displaying of the array, the program displays the following:
[R]everse [A]dd [S]earch E[xit]
Please select an option:_

Then, if the user selects:
- R (lowercase or uppercase): the program displays the reversed version of the array.
- A (lowercase or uppercase): the program displays the sum of the elements of the array.
- S (lowercase or uppercase): the program asks the user to insert an integer number and
look for it in the array, returning a message whether the number is found and its position
(including multiple occurrences, see example below), or is not found.
- E (lowercase or uppercase): the program exits.

NOTE: Until the last option (ā€˜eā€™ or ā€˜Eā€™) is selected, the main program comes back at the
beginning, asking the user to insert a new integer number.
---------------------------- end assignment ------------------------------------------------
intializeArrayRandomly(numbers, ELEMENTS);
What kind of object is numbers? What kind of object does this function expect as the first parameter?


1
2
3
	int distributionToss;
	std::mt19937 generator(std::random_device{}());
	std::uniform_int_distribution<int> distributionToss(min, max); //sets n 

On the first line there, you're creating an object named distributionToss. On the third line there, you're creating an object named distributionToss. This is a problem. You can't create two objects with the same name.



You're missing the <random> header include.
@ kaylah93, Moschops explained it better than I could. Furthermore, the reason I gave you a little hint with the random numbers is to change the old format:

1
2
3
4
5
6
7
8
srand(time(0));
int search, array[10]; // 
int x;
for ( int x = 0; x < 10; x++ ) // 
	{
	cout << setw(3) << ( rand() % (100 - 60 +1) + 60);// Prints out 9 random numbers between 60 and 100
	int srand[10] = {rand() % 40 + 61}; //puts a number into array
	}


to the one I typed above.

Also, be careful when you are naming the variables/objects. On line 23 and line 25 has very similar name : number and numbers. Although C++ will let you do it (since it is not the same), it could cause troubles later on when you are writing hundreds of line of code.

The output should look something close to this:
https://www.youtube.com/watch?v=QhKraD0s72k
Thanks for all the help guys
Topic archived. No new replies allowed.