Spits out random numbers/letters

Runs OK but spits random code.

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
#include <iostream>
#include <ctime>
#include <string>

using namespace std;


string characterGenPrGood();

void goodGen();

int main()
{

	unsigned seed = time(0);

	srand(seed);

	int choice;
	int again = 3;

	cout << "Welcome to character generator!" << endl;

	
	
	do
	
	{

	cout << "Type 1 for good character and 2 for a bad character." << endl;
	
	cin >> choice;



	while (choice != 1 && choice != 2)
	{
		cout << "Invalid choice. Enter 1 for good or 2 for bad." << endl;

		cin >> choice; 

	}

	if (choice == 1)

		goodGen();



	}while(again != 1);

	cout << "Good luck with your story! Glad I could help!";


         return 0;}


string characterGenPrGood()
{
	const int SIZE = 11;
	
	string adjective[SIZE] = {"affectionate","debonair", "dependable", "faithful", "generous", "kind", "self-disciplined", "Warmhearted", "thoughtful", "patient", "sensible"};
	
	int choice = rand() %10 + 0; 

	string adjchoice = adjective[choice];

	return adjchoice;

}

void goodGen()
{

	cout << "You chose good." << endl;
	
	bool gender; 

	gender = rand() %1 + 0;

	if (gender= true)
	
	cout << "The character is a girl." << endl << "THe character is ";

	else

	cout << "The character is a boy." << endl << " The character is ";

	for(int i = 0; i < 2; i++)
	{

		cout << " " << characterGenPrGood() << " " << characterGenPrGood << endl;

	}
}
Hi,

Make the compiler work for you, I used cpp.sh (the gear icon top right of the code), with all 3 warnings on:

 In function 'void goodGen()': 
81:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 
92:49: warning: the address of 'std::string characterGenPrGood()' will always evaluate as 'true' [-Waddress]


Change line 81 to if (gender)

Missing some parentheses on line 92.
Thanks a lot! I appreciate it. Dunno why I didn't look at the compiler. Did this for fun to brush up on what I learned in C++ before I take java next semester. I appreciate it!
Topic archived. No new replies allowed.