Getting a random number between 13 and 15

Hey there, I need some help with a program I am making. When you type in certain text, it randomly prints from set responses. I have it using the random function in order to print responses, however, I am having a problem. I keeps printing out irrelevant text EX: You enter "Fight me" It'll say " "Goodbye." which is a response to if you say "hello"
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
  #include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#pragma comment(lib, "Winmm.lib")

using namespace std;
int main() {
	string c;
	int re;
	cout << "			Welcome to S.A.M." << endl;
	cout << endl;
	cout << endl;
	cout << "		Please refrain from using Captaial Letters or Special Charcters while using S.A.M.! It makes him Angry!" << endl;
	cin >> c;
	if (c == "hi" || "hello" || "hi sam" || "hello there" || "hello sam" || "hey" || "sup" || "hey there sam") {
		srand(time(0));
		re = rand() % 8 + 1;
		if (re == 1) {
			cout << "What's up you piece of trash." << endl;
			cin >> c;
		}
		if (re == 2) {
			cout << "Goodbye." << endl;
			cin >> c;
		}
		if (re == 3) {
			cout << "Fuck off my dude." << endl;
			cin >> c;
		}
		if (re == 4) {
			cout << "Why hello there, asshole." << endl;
			cin >> c;

		}
		if (re == 5) {
			cout << "Did I give you permission to greet me? Didn't think so." << endl;
			cin >> c;
		}
		if (re == 6) {
			cout << "Fuck off." << endl;
			cin >> c;
		}
		if (re == 7) {
			cout << "Greetings are for faggots, faggot." << endl;
			cin >> c;
		}
		if (re == 8) {
			cout << "Don't try and talk to me until you lose your virginity, m'kay?" << endl;
			cin >> c;
		}
		
	}
	if (c == "lets play" || "want to play a game" || "want too play a game" || "wanna play a game" || "lets do something" || "lets play something") {
		re = rand() % 9 + 12;
		if (re == 9) {
			cout << "I'd rather not." << endl;
			cin >> c;
		}
		if (re == 10) {
			cout << "Let's play the game, 'who should we eat first' and then not make it a game." << endl;
			cin >> c;
		}
		if (re == 11) {
			cout << "Anything but COD" << endl;
			cin >> c;
		}
		if (re == 12) {
			cout << "I'd rather hang from a noose" << endl;
			cin >> c;
		}
	}
	if (c == "fight me" || "lets fight" || "wanna go") {
		re = rand() % 15 + 13 ;
		if (re == 13) {
			cout << "I don't fight 12 year olds who play TF2, but if you insist." << endl;
			cin >> c;
		}
		if (re == 14) {
			cout << "Gary Johnson has a better chance of winning the 2016 election than you do beating me in a fight." << endl;
			cin >> c;
		}
		if (re == 15) {
			cout << "I will destroy you like Lisa will destroy ISIS." << endl;
			cin >> c;
		}
		else {
			re = rand() % 1000 + 1010;
			if (re == 1000) {
				cout << "Don't make me tell Hillary Clinton that you have information that could lead to her arrest." << endl;
				cin >> c;
			}
			if (re == 1001) {
				cout << "You smell like the rotten asshole of a roadkill skunk that was drenched in beer." << endl;
				cin >> c;
			}
		}
	}


}
You have two issues as far as I can tell.

1.

Your if statement. This for example - (c == "fight me" || "lets fight" || "wanna go")
Is wrong. You have to explicitly type c == everytime. It should look like this -

(c == "fight me" || c == "lets fight" || c == "wanna go") // Note c== after every ||


2.


cin >> c; The "cin" operator stops reading at white space. So if you type "Fight me" It will stop after "fight". "me" will not be read. What you have to use to get the entire sentence with space is called getline - http://www.cplusplus.com/reference/string/string/getline/
Last edited on
closed account (LA48b7Xj)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int RandInt(int low, int high)
{
    return low + rand()%(high - low + 1);
}

int main()
{
    srand(time(nullptr));
    int number = RandInt(13, 15);
    cout << number << '\n';
}


Does that help?
Last edited on
Topic archived. No new replies allowed.