Random Number Generator Question

Hello,
for my assignment we need to create a code that generates
1. n number of random numbers (from 0-100) and store them in an array
2. then we have to ask the user a question if they want to see the numbers in the array
3. then ask the user if they want to see the numbers in the array in order from 0-100
4. then ask the user if they want to see the histogram of the data set
5. finally, ask the user if they want to see the number of data in the array, the max, the min, the standard deviation, average, variance.

I am however, finding it hard for the program to display the numbers of the array if the user says 'y' the question (AKA step 2)

Any help is great

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
 #include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

int main()
{
    
    int numb=0;
    int *newar=NULL;
    char response;
    cout << "enter integer:";
    cin >> numb;
    
    newar = new int [numb];
    
    
    for(int i=0;i<numb;i++)
    {
        newar[i]=rand() % 101;
        
    
    
    
    cout << "Do you want to see array? (Y/N) :";
    cin>> response;
    if (response != 'n')
    {
        cout<<newar[i]<<" ";
    }
    }
    return 0;
    
    
}
closed account (48T7M4Gy)
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
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

int main()
{
    
    int numb = 0;
    int *newar = nullptr;
    char response;
    cout << "enter integer:";
    cin >> numb;
    
    newar = new int [numb];
    
    
    for(int i=0;i<numb;i++)
    {
        newar[i]=rand() % 101;
    }
    
    cout << "Do you want to see array? (Y/N) :";
    cin>> response;
    if (response != 'n'){
        for( int i = 0; i < numb; i++){
            cout<<newar[i]<<" ";
        }
    }
    
    return 0;
}
closed account (48T7M4Gy)
A more positive way to ask the question, and there are many permutations of this to take into account a 'n' response.

1
2
3
4
5
6
7
cout << "Do you want to see array? (Y/N) : ";
    cin>> response;
    if (toupper(response) == 'Y'){
        for( int i = 0; i < numb; i++){
            cout<<newar[i]<<" ";
        }
    }
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
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;

void max(int*,int);
void search(int*, int);
void min(int*, int);

int main()
{
	srand(time(0));
	char choice;
	int *arr = nullptr, size = 0;
	cin >> size;
	arr = new int[size];
	for (int i = 0; i < size; i++)
	{
		arr[i] = rand() % 100;
	}

	cout << "\n1-Find Number in the Array\n";
	cout << "\n2-Min\n";
	cout << "\n3-Max\n";
	cout << "\nEnter The Choice : ";
	cin >> choice;
	if (choice == '1')
		search(arr, size);
	else if (choice == '2')
		min(arr, size);
	else if (choice == '3')
		max(arr, size);
	else
		cout << "\nEnter The Invalid Input\n";

	system("pause");
}

void max(int *arr, int size)
{
	int num = arr[0];
	for (int i = 0; i < size; i++)
	{
		if (arr[i]>num)
			num = arr[i];
	}
	cout << "\nThe Maximum Number is : " << num;
}

void min(int *arr, int size)
{
	int num = arr[0];
	for (int i = 0; i < size; i++)
	{
		if (arr[i]<num)
			num = arr[i];
	}
	cout << "\nThe Minimum Number is : " << num;
}

void search(int *arr, int size)
{
	int num = arr[0];
	bool flag = true;
	for (int i = 0; i < size; i++)
	{
		if (num == arr[i])
		{
			flag = false;
		}
	}
	if (flag == true)
		cout << "\nNumber is found\n";
	else
		cout << "\nNumber is not found\n";
}

bird1234: what's with all the C header files
closed account (48T7M4Gy)
@gunnerfunner
what's with all the C header files

I used them too, simply because OP used them. It's not relevant to OP's problem and some ppl are using outdated/different systems. Whether that was bird1234's reason or not we'll have to wait by the look of it.
Topic archived. No new replies allowed.