Problem with displaying

Hello so I'm trying to get this to run but I can't seem to find the problem. I need to get the function to work when they type in a letter but none of them display. I'm also having trouble with the very last line asking to play again.

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
105
106
107
108
109
110
111
 #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

void love()
{
	srand(time(0));
	int result = rand() % 5;
	switch (result)
	{
	case'A':
	cout << "The next person you meet with black hair is your lover." << endl;
	break;
	case 'B':
	cout << "Watch out for someone with blue eyes." << endl;
	break;
	case 'C':
	cout << "You and your next partner will live together very long." << endl;
	break;
        case'D':
	cout << "The love of your life is right around the corner. " << endl;
	break;
	case'E':
	cout << "It is best you wait for someone to come to you." << endl;
	break;
	}
}

void future()
{
	srand(time(0));
	int result = rand() % 5;
	switch (result)
	{
	case'A':
	cout << "You will be a businessman with your own tower named after you. " << endl;
	break;
	case'B':
	cout << "McDonalds is the way to go." << endl;
	break;
	case'C':
	cout << "You are a journalist that travels the world and documents everything." << endl;
	break;
	case'D':
	cout << "Just sit back and relax." << endl;
	break;
	case'E':
	cout << "You are a teacher working a 9-5 everyday." << endl;
	break;
	}
}

void finance()
{
	srand(time(0));
	int result = rand() % 5;
	switch (result)
	{
	case'A':
	cout << "You will be a billionare!" << endl;
	break;
	case'B':
	cout << "You should probably stop going to clubs every week." << endl;
	break;
	case'C':
	cout << "Maybe you should get that lottery ticket. " << endl;
	break;
	case'D':
	cout << "Money will not be a problem for you. " << endl;
	break;
	case'E':
	cout << "Start saving up." << endl;
	break;
	}
}

int main()
{
	int lucky;
	int letter;
	char playAgain;

	cout << "Welcome to the Psychic Computer Network. " << endl;
	cout << "Enter your lucky number: ";
	cin >> lucky;
	do
	{
		{
			cout << "\nEnter the letter 'L' to find out about your love life." << endl;
			cout << "Enter the letter 'F' to find out your future in 30 years." << endl;
			cout << "enter the letter 'G' to find out about your financial situation." << endl;
			cin >> letter;
			if (letter == 'L' || letter == 'l')
				love();
			else if (letter == 'F' || letter == 'f')
				future();
			else if (letter == 'G' || letter == 'g')
				finance();
		}

		cout << "would you like another prediction?(y/n): "<<endl;
		cin >> playAgain;
	}
	while (playAgain == 'y');

	if (playAgain == 'n')
		 return 0;
	
	
}
Last edited on
1
2
3
4
int result = rand() % 5;
	switch (result)
	{
	case'A':


'A' is a character. result is an integer.
You're allowed to make this comparison, but upper-case 'A' for example has a decimal value of 65, which isn't within your 0 - 5 range - neither are any of the other cases.

Additionally, you should call srand once and only once at the beginning of your program unless you have some specialized reason for doing so.
Topic archived. No new replies allowed.