My Project: Dinjy

Pages: 12
That's usually when I tend to lurk hehe...

Ok, here's basically what it would be (only for the first one):

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
void earth()
{
// Variables ********************************
	string line1, line2, line3, line4, line5, line6, line7;
	string choice;
	int HP;
	int PP;
	int Att;
	int Def;
	int Agi;
	int Lck;
	ofstream current;
	ofstream results;
	ifstream stats;
	ifstream flint;
	ifstream granite;
	ifstream quartz;
	ifstream vine;
	ifstream sap;
	ifstream ground;
	ifstream bane;

// Helpful output for the user to follow *********************
	cout << endl << endl;
	cout << "Welcome, Earth Adept!" << endl;
	cout << "Select Earth Djinni from below:" << endl << endl;
	cout << "________ HP  PP  Att  Def  Agi  Lck" << endl;
	cout << "Flint    8   4   3    --   --   --" << endl;
	cout << "Granite  9   --  --   2    2    1" << endl;
	cout << "Quartz   10  3   --   --   3    --" << endl;
	cout << "Vine     12  4   --   3    --   1" << endl;
	cout << "Sap      10  --  3    --   --   1" << endl;
	cout << "Ground   9   3   --   --   3    --" << endl;
	cout << "Bane     12  --  4    --   --   --" << endl;
	cout << "________" << endl << endl;
	stats.open("isaacstats.txt");
	stats >> HP >> PP >> Att >> Def >> Agi >> Lck;
	stats.close();
	current.open("current.txt");
	current << "-Isaac-" << endl;
	current << "HP:  " << HP << endl;
	current << "PP:  " << PP << endl;
	current << "Att: " << Att << endl;
	current << "Def: " << Def << endl;
	current << "Agi: " << Agi << endl;
	current << "Lck: " << Lck;
	cout << "-Current-" << endl;
	cout << "HP:  " << HP << endl;
	cout << "PP:  " << PP << endl;
	cout << "Att: " << Att << endl;
	cout << "Def: " << Def << endl;
	cout << "Agi: " << Agi << endl;
	cout << "Lck: " << Lck << endl;
	current.close();
// If statements for each Djinni to be called with
	cout << endl;
	cout << "Earth Djinni: ";
	cin >> choice;
	cout << endl;
	if (choice == "flint" || choice == "Flint" || choice == "FLINT"){
		flint.open("flint.txt");
		// read text
		getline(flint, line1);
		getline(flint, line2);
		getline(flint, line3);
		// write text
		cout << "You teamed up with Flint!" << endl << endl;
		cout << "-Stats Added-" << endl;
		cout << "HP:  " << line1 << endl;
		cout << "PP:  " << line2 << endl;
		cout << "Att: " << line3 << endl << endl;
                HP += 8; //increment the variables by their correct amounts
                PP += 4;
                Att += 3;
                flint.close();
	} //do same for others
        //since the following code is basically the same for everything else
        //we don't need it inside each if
        // write results to results.txt
	results.open("results.txt");
	results << "-Isaac-" << endl;
	results << "HP:  " << HP << endl;
	results << "PP:  " << PP << endl;
	results << "Att: " << Att << endl;
	results << "Def: " << Def << endl;
	results << "Agi: " << Agi << endl;
	results << "Lck: " << Lck;
	// write results to console
	cout << "Update!" << endl << endl;
	cout << "-Isaac-" << endl;
	cout << "HP:  " << HP  << endl;
	cout << "PP:  " << PP << endl;
	cout << "Att: " << Att << endl;
	cout << "Def: " << Def << endl;
	cout << "Agi: " << Agi << endl;
	cout << "Lck: " << Lck << endl << endl;
thanks for that, i love this method better, it shortens my code a lot, much appreciated!! but i'm still unable to figure out how to update what "current" stats display, i know why it does this but not sure how i can fix it.. it does this still:
http://i44.photobucket.com/albums/f20/shadowclone666/issue.png
this is why:
1
2
3
4
5
6
7
cout << "-Current-" << endl;
	cout << "HP:  " << HP << endl;
	cout << "PP:  " << PP << endl;
	cout << "Att: " << Att << endl;
	cout << "Def: " << Def << endl;
	cout << "Agi: " << Agi << endl;
	cout << "Lck: " << Lck << endl;

It is assigned to the HP PP Att Def Agi Lck variables which are assigned the values of 38 23 17 8 12 3. I only did THAT because the FIRST time i load the program i need that to happen so the stats start out properly, but i'd like it to display updated stats to the console where it says "Current" by keeping track of which combo of 7 djinni names i pick from any element. Then it can either repeat entirely from scratch or shut down and record final stats into results.txt

get what i'm saying? >_> its so confusing ._.

(edit): i also just tried to loop the if statements 7 times with this for loop:
1
2
3
4
for (choice = 0; choice < 8; choice ++)
{
//if statements
}

but it always errored on me lol...that was my best guess at having djinni selection loop 7 times.
Last edited on
Well it's probably because you are still reading from the "current.txt" file, which contains the old data from the beginning of the earth(). You will either need to update "current.txt" again, or read from the "results.txt" file.
well idk what you mean by update current.txt again. so i'm trying to get console to display data from the output file "results.txt" after user selects djinni. problem is, i'm not too sure how i would display to the console something from an output text file... it always errors me. and getline doesn't work with ofstream for some reason ._.
getline doesn't work with oftreams because they are meant for output.
Try declaring results as fstream so you can use it both for input and output.
Last edited on
well fstream certainly does the job of in/out lol...should've known that..

and now i'm trying to figure out the best way to make this program update and display stats up to 7 times. its killin' me -_- nothing i'm doing seems to even make sense anymore @_@
Just make a for loop around the code:

1
2
3
4
for (int i = 0; i < 7; ++i) {
   //do your stuff
}
//done 
lol yea it makes sense like that, but for some weird reason and for the first time using a for loop, it errors. my code is conjumbled -_-
This a random guess but...

1
2
3
4
5
6
7
8
9
void Function() {
   //get their type
   if(type == "earth") {
      for(int i = 0; i < 7; ++i) {
         earth();
      }
   } else if(/*etc*/) {
   }
}
remember my 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
	// If statements for each Djinni to be called with
	cout << endl;
	cout << "Earth Djinni: ";
	cin >> choice;
	cout << endl;
	if (choice == "flint" || choice == "Flint" || choice == "FLINT"){
		flint.open("flint.txt");
		// read text
		getline(flint, line1);
		getline(flint, line2);
		getline(flint, line3);
		// write text
		cout << "You teamed up with Flint!" << endl << endl;
		cout << "-Stats Added-" << endl;
		cout << "HP:  " << line1 << endl;
		cout << "PP:  " << line2 << endl;
		cout << "Att: " << line3 << endl;
		cout << "______________________________________" << endl;
		// increment the variables by their correct amounts
		HP += 8;
		PP += 4;
		Att += 3;
		flint.close();
	}


i'll not include each djinni code for prettiness sake >_>, but i need to know how i can terminate the console if the user enters "q" for int choice
instead of a djinni name from the list.

i've tried while loop, and if loop. can't seem to get the program to quit if user inputs "q" instead of a name.
Since earth is a void(), just return if you get a 'q' as the input.
Since earth is a void(), just return if you get a 'q' as the input.

yea that sorta made sense so i tried return "q"; but it didn't work because it said a void can't return a value, and since you're good at c++ i'm sure you weren't talking about return "q";

on to my other issue:

i have a weird one this time, after the program runs and when i complete function earth (all elements actually, but using only earth to avoid pasting lots of code) the "lck: " part of stats always glitches...and shows weird random numbers in addition to what i really want. this is the neucense i refer to:
http://i44.photobucket.com/albums/f20/shadowclone666/LckScrewy.png

and this is the 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
void earth()
{
// Variables ********************************
	string line1, line2, line3, line4, line5, line6, line7, line8;
	string choice;
	int floop;
	int HP;
	int PP;
	int Att;
	int Def;
	int Agi;
	int Lck;
	fstream results;
	ifstream stats;

// Helpful output for the user to follow *********************
	for (int floop = 0; floop < 7; ++floop){
		cout << "______________________________________" << endl;
		cout << "Welcome, Earth Adept!" << endl;
		cout << "Select Earth Djinni from below:" << endl << endl;
		cout << "________ HP  PP  Att  Def  Agi  Lck" << endl;
		cout << "Flint    8   4   3    --   --   --" << endl;
		cout << "Granite  9   --  --   2    2    1" << endl;
		cout << "Quartz   10  3   --   --   3    --" << endl;
		cout << "Vine     12  4   --   3    --   1" << endl;
		cout << "Sap      10  --  3    --   --   1" << endl;
		cout << "Ground   9   3   --   --   3    --" << endl;
		cout << "Bane     12  --  4    --   --   --" << endl;
		cout << "________" << endl << endl;

		stats.open("isaacstats.txt");
		stats >> HP >> PP >> Att >> Def >> Agi >> Lck;
		stats.close();

		// write current stats to console
		cout << "-Current-" << endl;
		cout << "HP:  " << HP << endl;
		cout << "PP:  " << PP << endl;
		cout << "Att: " << Att << endl;
		cout << "Def: " << Def << endl;
		cout << "Agi: " << Agi << endl;
		cout << "Lck: " << Lck << endl;

		// If statements for each Djinni to be called with
		cout << endl;
		cout << "Earth Djinni: ";
		cin >> choice;
		cout << endl;
		if (choice == "flint" || choice == "Flint" || choice == "FLINT"){
			cout << "You teamed up with Flint!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  8" << endl;
			cout << "PP:  4" << endl;
			cout << "Att: 3" << endl;
			cout << "______________________________________" << endl;
			// increment the variables by their correct amounts
			HP += 8;
			PP += 4;
			Att += 3;
		}
		if (choice == "granite" || choice == "Granite" || choice == "GRANITE"){
			cout << "You teamed up with Granite!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  9" << endl;
			cout << "Def: 2" << endl;
			cout << "Agi: 2" << endl;
			cout << "Lck: 1" << endl;
			cout << "______________________________________" << endl;
			HP += 9;
			Def += 2;
			Agi += 2;
			Lck += 1;
		}
		if (choice == "quartz" || choice == "Quartz" || choice == "QUARTZ"){
			cout << "You teamed up with Quartz!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  10" << endl;
			cout << "PP:  3" << endl;
			cout << "Agi: 3" << endl;
			cout << "______________________________________" << endl;
			HP += 10;
			PP += 3;
			Agi += 3;
		}
		if (choice == "vine" || choice == "Vine" || choice == "VINE"){
			cout << "You teamed up with Vine!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  12" << endl;
			cout << "PP:  4" << endl;
			cout << "Def: 3" << endl;
			cout << "Lck: 1" << endl;
			cout << "______________________________________" << endl;
			HP += 12;
			PP += 4;
			Def += 3;
			Lck += 1;
		}
		if (choice == "sap" || choice == "Sap" || choice == "SAP"){
			cout << "You teamed up with Sap!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  10" << endl;
			cout << "Att: 3" << endl;
			cout << "Lck: 1" << endl;
			cout << "______________________________________" << endl;
			HP += 10;
			Att += 3;
			Lck += 1;
		}
		if (choice == "ground" || choice == "Ground" || choice == "GROUND"){
			cout << "You teamed up with Ground!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  9" << endl;
			cout << "PP:  3" << endl;
			cout << "Agi: 3" << endl;
			cout << "______________________________________" << endl;
			HP += 9;
			PP += 3;
			Agi += 3;
		}
		if (choice == "bane" || choice == "Bane" || choice == "BANE"){
			cout << "You teamed up with Bane!" << endl << endl;
			cout << "-Stats Added-" << endl;
			cout << "HP:  12" << line1 << endl;
			cout << "Att: 4" << line2 << endl << endl;
			cout << "______________________________________" << endl;
			HP += 12;
			Att += 4;
		}
		
		// write results to results.txt
		results.open("results.txt");
		results << "-Isaac-" << endl;
		results << "Earth Adept" << endl;
		results << "HP:  " << HP << endl;
		results << "PP:  " << PP << endl;
		results << "Att: " << Att << endl;
		results << "Def: " << Def << endl;
		results << "Agi: " << Agi << endl;
		results << "Lck: " << Lck;		
		results.close();

	} // end of loop

	// read first 7 lines in results.txt
	results.open("results.txt");
	getline(results, line1);
	getline(results, line2);
	getline(results, line3);
	getline(results, line4);
	getline(results, line5);
	getline(results, line6);
	getline(results, line7);
	getline(results, line8);
	results.close();

	// display results.txt to console
	cout << line1 << endl;
	cout << line2 << endl;
	cout << line3 << endl;
	cout << line4 << endl;
	cout << line5 << endl;
	cout << line6 << endl;
	cout << line7 << endl;
	cout << line8 << endl;

} // end function earth 


and after i quit the console, i check my results.txt and it looks weird like this:
http://i44.photobucket.com/albums/f20/shadowclone666/resultstxt.png
instead of what i want:
-Isaac-
Earth Adept
HP: 108
PP: 23
Att: 38
Def: 8
Agi: 12
Lck: 10
Last edited on
Yeah, I meant just use return;.

Hmm, well some things I noticed:

1.) Don't bother writing to results.txt after each loop, just write it after you get out of the for loop

Well, if you selected one of every guy, you do get the stats in the file (except luck...that should only be 6)...You could try stepping through the code with a debugger and checking to see where the Luck variable gets bugged. I might be able to help you more tomorrow if I have some extra time.
Well, if you selected one of every guy, you do get the stats in the file (except luck...that should only be 6)...You could try stepping through the code with a debugger and checking to see where the Luck variable gets bugged. I might be able to help you more tomorrow if I have some extra time.

so you see how its confusing me? well would it help if i sent all my code to you? i'll have to go to bed now too, i'll be on tomorrow.

and i cleaned up my code again with your advice.
Yeah, I'll run it through my debugger when I have the time. Send me an e-mail at firedraco2@yahoo.com
Topic archived. No new replies allowed.
Pages: 12