-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandomNumberGenerator.cpp
More file actions
51 lines (38 loc) · 959 Bytes
/
RandomNumberGenerator.cpp
File metadata and controls
51 lines (38 loc) · 959 Bytes
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
// Random Number Generator from 0 to 100
#include <iostream>
using namespace std;
int main() {
srand(time(NULL));
int num = (rand() % 100) + 1;
cout << num << endl;
return 0;
}
// =========================================
// Another application:
#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
{
srand(time(0)); // Seed the random number generator
int randNum = rand() % 5 + 1; // Generates a random number between 1 and 5
switch(randNum)
{
case 1:
std::cout << "You win a bumper prize!\n";
break;
case 2:
std::cout << "You win a t-shirt!\n";
break;
case 3:
std::cout << "You win a free lunch!\n";
break;
case 4:
std::cout << "You win a gift card!\n";
break;
case 5:
std::cout << "You win concert tickets!\n";
break;
}
return 0;
}