-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrandNumGen.cpp
104 lines (86 loc) · 2.15 KB
/
randNumGen.cpp
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
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <vector>
using namespace std;
//menu title
void TitleBlockRandNum(){
cout << endl;
cout << "GENERATE RANDOM NUMBERS" << endl;
}
//claculate total sum
int GetSum(vector<int> randNums, int vectorSize){
int total = 0;
for (int i = 0; i < vectorSize; i++){
total = total + randNums.at(i);
}
return total;
}
//print footer details
void PrintVectorDetails(vector<int> randNums, int vectorSize){
cout << endl;
cout << "---------------" << endl;
cout << "Sum of all numbers: " << GetSum(randNums, vectorSize);
}
//** RANDOM NUMBER GENERATORS **//
int vectorSize = 1000;
vector<int> randNums(vectorSize);
int GenerateRandomNumber(int seed = 0){
srand(time(NULL) + seed); //use date + time as rand seed
int randomNumber = rand() % 10; //rand range 0 - 9
return randomNumber;
}
void xGenerateRandomNumber(vector<int>& randNums, int& vectorSize){
TitleBlockRandNum();
cout << "How many numbers do you need (1000 max): ";
cin >> vectorSize;
system("clear");
TitleBlockRandNum();
cout << "Numbers Generated: ";
for(int i = 0; i < vectorSize; i++){
randNums.at(i) = GenerateRandomNumber(i);
cout << randNums.at(i);
}
cout << endl;
}
void AllGenerateRandomNumber(vector<int>& randNums, int& vectorSize){
srand(time(NULL));
vectorSize = rand() % 1000;
system("clear");
TitleBlockRandNum();
cout << "Numbers Generated: ";
for(int i = 0; i < vectorSize; i++){
randNums.at(i) = GenerateRandomNumber(i);
cout << randNums.at(i);
}
cout << endl;
}
//** SWITCH CASE STATEMENTS **//
void RandomNumberCase(int menuSelection){
switch (menuSelection) {
case 1:
system("clear");
TitleBlockRandNum();
cout << "Number Generated: ";
cout << GenerateRandomNumber() << endl;
cout << endl;
break;
case 2:
system("clear");
xGenerateRandomNumber(randNums, vectorSize);
PrintVectorDetails(randNums, vectorSize);
cout << endl;
break;
case 3:
system("clear");
AllGenerateRandomNumber(randNums, vectorSize);
cout << endl;
break;
default:
cout << "Exiting: number picked is outside the parameters." << endl;
cout << endl;
break;
}
}