functions are a pain ... im lost and out of time

We are learning c++ at school for the first time and this is our final progect.
A text based RPG
Its based around Lord of the Flies (survive in the wild)
so we made functions and they are supose to return all the variables that were sent in to them, but we are not sure how functions even work, and this stuff is like due monday morning.
pls help <3
posted twice cause the code was to long ;D


//Includes
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include "windows.h"
#include "string"
#include <fstream>
#include <conio.h>
#include <mmsystem.h>
using namespace std;

int iRescue = 1;
int iTime = 500;
//Difficulty Integers
int iLevel = 0;
int iLevelCost = 0;
//Character integers (Stats and stuff)
int iChar = 0;
int iCharF = 0;
int iCharW = 0;
int iCharH = 0;
int iCharL = 0;
int iCharS = 0;
//Days Integer
int iDays = 1;
int iDayTime = 0;
//Menu Integer
int iMenu = 0;
//Action Integers
int iFire = 0;
int iShelter = 0;
int iShelterMade = 0;
int iDaysShelter = 0;
int iLeaf = 0;
int iWood = 0;
int iFood = 0;
void Display (int iTime, int iLevel, int iLevelCost, int iChar, int iCharF, int iCharW, int iCharL, int iCharH, int iCharS, int iDays, int iDayTime, int iFire, int iShelter, int iShelterMade, int iDaysShelter, int iLeaf, int iWood, int iFood)
{
cout << "You have "<< iTime << " Time left on the island.\n";
//Difficulty Integers
cout << "Your difficulty is level "<< iLevel << " and the cost of actions increase by " << iLevelCost <<".\n";
//Character integers (Stats and stuff)
cout << "Your Stats are :\n";
cout << "Fire making abilities : "<< iCharF << ".\n";
cout << "Wood wfinding abilities : "<< iCharW << ".\n";
cout << "Hunting abilities : "<< iCharH << ".\n";
cout << "Leave finding abilities : "<< iCharL << ".\n";
cout << "Shelter building abilities : "<< iCharS << ".\n";
//Days Integer
cout << "You have been on the island for "<< iDays << " days.\n";
//Action Integers
cout << "You have " << iFire << " fires.\n";
cout << "You have " << iWood << " pieces of wood.\n";
cout << "You have " << iShelter << " shelters, that have been up for " << iDaysShelter << " days.\n";
cout << "You have " << iFood << " pieces of food.\n";
cout << "You have " << iLeaf << " leaves.\n";
Sleep (7500);
return;
}
//<------------------------ rescue function
int Died (int iLevel, int iDays, int iChar, int iTime, int iRescue)
{
int iFate;
int iChance = 0;
int iRescueChance = 0;
iFate= rand() % 10 + 1;
iChance = (iDays * 5) + (iChar * 50)- iLevel ;
iRescueChance= rand() % 100 + 1;
if (iRescueChance <= iChance)
{
iRescue = 0;
cout <<"You have been rescued\n";
while (iTime >= 500)
{
cout <<"You returned home safely\n";
Sleep (10000);
break;
}
while(iTime>=350)
{
cout <<"You are sent to the hospital\n";
if (iFate <=8)
{
cout <<"You go home healthy\n";
Sleep (10000);
}
else
{
cout <<"You have died\n";
Sleep (10000);
}
break;
}
while (iTime>= 250)
{
cout <<"You have been sent to the hospital\n";
if (iFate <= 5)
{
cout <<"You go home healthy\n";
Sleep (10000);
}
else
{
cout <<"You have died\n";
Sleep (10000);
}
break;
}
while (iTime<250)
{
cout<<"You have been sent to the hospital\n";
if (iFate <= 3)
{
cout<<"You go home healthy\n";
Sleep (10000);
}
else
{
cout<<"You have died\n";
Sleep (10000);
}
}
}
else
{
cout << "you were not saved\n";
Sleep(10000);
}
return 0;
}
//FIRE FUNTION<---------------------------------
int Fire(int iWood, int iLevel, int iLevelCost, int iCharF, int iDays, int iTime, int iFire, int iDayTime)
{
if (iWood >= 10)
{
int iChance = 0;
int iCost = 0;
iCost = 30 + iCharF + iLevelCost;
iChance = iLevel + (iDays *5) + iCharF;
iFire= rand() % 100 + 1;
iTime -= iCost;
if(iFire <= iChance)
{
iWood -= 10;
cout<<"You made a fire";
}
else
{
cout<<"You failed, no fire was made, and you lost 10 wood. Nubs.....\n";
}
}
else
{
cout<<"You dont have enough wood\n";
}
return 0;
}
//Wood FUNTION<---------------------------------
int Wood(int iLevel, int iLevelCost, int iCharW, int iTime, int iWood, int iDays, int iDayTime)
{
int iWoodChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 15 + iCharW + iLevelCost;
iChance = iLevel - (iDays *5) + iCharW;
iWoodChance= rand() % 100 + 1;
if(iWoodChance <= iChance)
{
iWood = iWood + iWoodChance/5;
iTime = iTime - iCost;
iTime -= iCost;
}
else
{
iTime -= iCost;
cout<<"You failed, no wood is found. Nubs.....\n";
}
return 0;
}
//Shelter FUNTION<---------------------------------
int Shelter(int iWood, int iLeaf, int iLevel, int iLevelCost, int iCharS, int iTime, int iShelter, int iDayTime, int iDays)
{
int iShelterChance = 0;
int iDayShelter = 0;
int iChance = 0;
int iCost = 0;
if (iShelter == 0)
{
if (iWood >= 10 && iLeaf >= 10)
{
iCost = 50 + iCharS + iLevelCost;
iChance = iLevel + (iDays *5) + iCharS;
iShelterChance = rand() % 100 + 1;
if(iShelter <= iChance)
{
iWood -= 10;
iLeaf -=10;
cout<<"You made a shelter";
iTime -= iCost;
iShelter = 1;
iDayShelter = iDays + 3;
}
else
{
cout<<"You failed, no shelter was made, and you lost 10 wood and 10 leaves. Nubs.....\n";
}
}
else
{
cout<<"You dont have enough wood or leaves, try again when you have 10 leaves and 10 wood\n";
}
}
else
{
cout<< "You allreay have a shelter";
}
return 0;
}
//LEAF FUNCTION <------------------------------------------------------------
int Leaf(int iLevel, int iLevelCost, int iCharL, int iTime, int iLeaf, int iDayTime, int iDays)
{
int iLeafChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 10 + iCharL + iLevelCost;
iChance = iLevel - (iDays *5) + iCharL;
iLeafChance = rand() % 100 + 1;
if(iLeafChance <= iChance)
{
iLeaf = iLeafChance/5;
iTime -= iCost;
}
else
{
cout<<"You failed, no leaves were found. Nubs.....\n";
}
return (iTime);
}
Last edited on
//Food FUNTION<---------------------------------
int Food(int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays)
{
int iFoodChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 15 + iCharF + iLevelCost;
iChance = iLevel - (iDays *5) + iCharF;
iFoodChance= rand() % 100 + 1;
if(iFoodChance <= iChance)
{
iFood = iFoodChance/5;
iTime -= iCost;
}
else
{
cout<<"You failed, no food is found. Nubs.....\n";
}
return;// (int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays); <---- doesnt return the variabels
}
int _tmain(int argc, _TCHAR* argv[])
{
//Remember to put in title <!@#!@%!@$@#!$@!%^!%^&*&%^(W#IUHAW^@&*$(#&@$~%^!@%!$~ERF
white();
cout << "WELCOME TO ";
bred();
cout << "LORD OF THE FLEAS\n";
white();
cout << "This is a Texted based RPG, that the developers were forced to make. \n We basically spent 2 weeks on the title screen, and a 48 hour session of coding on the weekend.";
cout << " We also were to lazy to make a story, so we are taking the plot of 'Lord of the Flies' by William Golding. So basically your flying away from Britian to get away";
cout << "from World War II, and your shot down and land on an island. Now you and other kids have to survive till you are rescued. ";
cout << " In order to have the most success you must use knowledge from the book to win. This Game helps your mathmatics and critical thinking.\n\n";
cout << "How skillful are you in the art of time wasting?\n";
cout << "Type 1 - Noob, Type 2 - Normal, Type 3 - Leet.\n";
cout << "Level : ";
bgreen();
cin >> iLevel;
white();
if (iLevel == 1)
{
iLevel = 50;
iLevelCost = 20;
}
else if (iLevel == 2)
{
iLevel = 40;
iLevelCost = 25;
}
else if (iLevel == 3)
{
iLevel = 30;
iLevelCost = 30;
}
else
{
cout << "Noob";
}
Sleep(2000);
Cls();
cout << "Who would you like to be to tackle this stuff?\n";
cout << "The stuff beisde each person is how it effects the cost for each action.\n";
cout << "So lets say I was Ralph and I wanted to make a fire, and the base cost is 30, so the cost would be 15 for me to make a fire.\n\n";
cout << "Type 1 - Ralph: Fire = -15, Wood = +15, Hunting = +20, Leaves = N/C, Shelter = -20\n";
cout << "Type 2 - Jack: Fire = +25, Wood = -10, Hunting = -25, Leaves = +5, Shelter = +5\n";
cout << "Type 3 - Piggy: Fire = -25, Wood = +20, Hunting = +35, Leaves = -10, Shelter = +20\n";
cout << "Character : ";
bblue();
cin >> iChar;
white();
if (iChar == 1) //Ralph
{
iCharF -= 20;
iCharW += 10;
iCharH += 10;
iCharL = 0;
iCharS -= 20;
}
else if (iChar == 2) //Jack
{
iCharF += 25;
iCharW -= 10;
iCharH -= 15;
iCharL += 5;
iCharS += 5;
}
else if (iChar == 3) //Piggy
{
iCharF -= 40;
iCharW += 20;
iCharH += 20;
iCharL -= 10;
iCharS += 20;
}
else
{
cout << "Noob";
}
Sleep(2000);
Cls();
cout << "My guess is you know what health points are, so your health points are called time. You will have an action menu to choose what to do.";
cout << " In order to survive you must keep warm, be fed and have water. It cost time to do actions. Good luck.";
Sleep(2000);
Cls();
while (iRescue == 1)
{
cout << "What do you want to do? You have ";
bpurple();
cout << iTime;
white();
cout << " Time.\n";
cout << "Type 1 to make a fire. (Lasts 1 day) (It will cost you 25 + Character + Level Cost)\n";
cout << "Type 2 to look for wood. (It will cost you 15 + Character + Level Cost)\n";
cout << "Type 3 to look for leaves. (It will cost you 5 + Character + Level Cost)\n";
cout << "Type 4 to hunt for food. (It will cost you 5 + Character + Level Cost)\n";
cout << "Type 5 to make a shelter. (It will cost you 40 + Character + Level Cost)\n";
cout << "Type 6 to display information.\n";
cin >> iMenu;
if (iMenu == 1)
{
Fire(iWood, iLevel, iLevelCost, iCharF, iDays, iTime, iFire, iDayTime);
}
else if (iMenu == 2)
{
Wood(iLevel, iLevelCost, iCharW, iTime, iWood, iDays, iDayTime);
}
else if (iMenu == 3)
{
Leaf(iLevel, iLevelCost, iCharL, iTime, iLeaf, iDayTime, iDays);
}
else if (iMenu == 4)
{
Food(iLevel, iLevelCost, iCharF, iTime, iFood, iDayTime, iDays);
}
else if (iMenu == 5)
{
if(iDays == iDaysShelter)
{
iShelterMade = 0;
}
Shelter(iWood, iLeaf, iLevel, iLevelCost, iCharS, iTime, iShelter, iDayTime, iDays);
}
else if(iMenu == 6)
{
Display(iTime, iLevel, iLevelCost, iChar, iCharF, iCharW, iCharL, iCharH, iCharS, iDays, iDayTime, iFire, iShelter, iShelterMade, iDaysShelter, iLeaf, iWood, iFood);
}
else
{
cout << "idk";
}
}
return 0;
}
Last edited on
so we made functions and they are supose to return all the variables that were sent in to them, but we are not sure how functions even work,


Check out the tutorial on functions on this site. Post again if you don't understand what is being said there.
Last edited on
so a function can return one number... but i need it to return 2 or 3
like for fire function , its needs to return
- how much time it took
- if the fire was even made
-how much wood is left after making fire
would this void thingy work
All variables declared in a function are local. All variables passed to functions, pass by value and makes hiden local copy. To use returned variables you must pass them by ref:

int myFunct(int i, int *j){
//some code
return 0;
}

int j;
myJ = myFunct(4,&j);

Then the value of j in function must returned to calling procces.
Sorry for my Enlgish.
local?
and will that return more than 1 or 2 variables, and what is & for
so confused :(
The other way is to use global variables declared before main{} but may be more confused.
&a returns the pointer of a, the memory address in that a stored. To do this a must declared before.
This is not confuse. Is a very clear schema to tell the mashine to do exactly you want. Design your function with this fact in mind and try it. :-)
Last edited on
already have global variables :D
If the concept of references is to difficult you could try passing pointers which is essentially the same thing in most cases.

And before anyone blasts me though that passing pointers is the same as passing a 'reference' let me clarify that I mean passing pointer arguments.

Ex.
return_type function_name(int * x)

instead of

return_type function_name(int & x)
Also for those trying to help you here is your code formatted:

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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//Includes
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include "windows.h"
#include "string"
#include <fstream>
#include <conio.h>
#include <mmsystem.h>

using namespace std;

int iRescue = 1;
int iTime = 500;

//Difficulty Integers 
int iLevel = 0;
int iLevelCost = 0;

//Character integers (Stats and stuff)
int iChar = 0;
int iCharF = 0;
int iCharW = 0;
int iCharH = 0;
int iCharL = 0;
int iCharS = 0; 

//Days Integer
int iDays = 1;
int iDayTime = 0;

//Menu Integer
int iMenu = 0;

//Action Integers
int iFire = 0;
int iShelter = 0;
int iShelterMade = 0;
int iDaysShelter = 0;
int iLeaf = 0;
int iWood = 0;
int iFood = 0;

void Display (int iTime, int iLevel, int iLevelCost, int iChar, int iCharF, int iCharW, int iCharL, int iCharH, 
                 int iCharS, int iDays, int iDayTime, int iFire, int iShelter, int iShelterMade, int iDaysShelter, 
                 int iLeaf, int iWood, int iFood)
{
    cout << "You have "<< iTime << " Time left on the island.\n";
    //Difficulty Integers 
    cout << "Your difficulty is level "<< iLevel << " and the cost of actions increase by " << iLevelCost <<".\n";
    //Character integers (Stats and stuff)
    cout << "Your Stats are :\n";
    cout << "Fire making abilities : "<< iCharF << ".\n";
    cout << "Wood wfinding abilities : "<< iCharW << ".\n";
    cout << "Hunting abilities : "<< iCharH << ".\n";
    cout << "Leave finding abilities : "<< iCharL << ".\n";
    cout << "Shelter building abilities : "<< iCharS << ".\n";
    //Days Integer
    cout << "You have been on the island for "<< iDays << " days.\n";
    //Action Integers
    cout << "You have " << iFire << " fires.\n";
    cout << "You have " << iWood << " pieces of wood.\n";
    cout << "You have " << iShelter << " shelters, that have been up for " << iDaysShelter << " days.\n";
    cout << "You have " << iFood << " pieces of food.\n";
    cout << "You have " << iLeaf << " leaves.\n";
    Sleep (7500);
    return;
}//<------------------------ rescue function
int Died (int iLevel, int iDays, int iChar, int iTime, int iRescue)
{
    int iFate;
    int iChance = 0;
    int iRescueChance = 0;
    iFate= rand() % 10 + 1;
    iChance = (iDays * 5) + (iChar * 50)- iLevel ;
    iRescueChance= rand() % 100 + 1; 
    if (iRescueChance <= iChance)
    {
        iRescue = 0;
        cout <<"You have been rescued\n";
        while (iTime >= 500)
        {
            cout <<"You returned home safely\n";
            Sleep (10000);
            break;
        }
        while(iTime>=350)
        {
            cout <<"You are sent to the hospital\n";
            if (iFate <=8)
            {
                cout <<"You go home healthy\n";
                Sleep (10000);
            }
            else
            {
                cout <<"You have died\n";
                Sleep (10000);
            }
            break;
        }
        while (iTime>= 250)
        {
            cout <<"You have been sent to the hospital\n";
            if (iFate <= 5)
            {
                cout <<"You go home healthy\n";
                Sleep (10000);
            }
            else
            {
                cout <<"You have died\n";
                Sleep (10000);
            }
            break;
        }
        while (iTime<250)
        {
            cout<<"You have been sent to the hospital\n";
            if (iFate <= 3)
            {
                cout<<"You go home healthy\n";
                Sleep (10000);
            }
            else
            {
                cout<<"You have died\n";
                Sleep (10000);
            }
        }
    }
    else
    {
    cout << "you were not saved\n";
    Sleep(10000);
    }
    return 0;
}

//FIRE FUNTION<---------------------------------
int Fire(int iWood, int iLevel, int iLevelCost, int iCharF, int iDays, int iTime, int iFire, int iDayTime)
{
    if (iWood >= 10)
    {
        int iChance = 0;
        int iCost = 0;
        iCost = 30 + iCharF + iLevelCost;
        iChance = iLevel + (iDays *5) + iCharF;
        iFire= rand() % 100 + 1; 
        iTime -= iCost;
        if(iFire <= iChance)
        {
            iWood -= 10;
            cout<<"You made a fire";
        }
        else
        {
            cout<<"You failed, no fire was made, and you lost 10 wood. Nubs.....\n";
        }
    }
    else
    {
        cout<<"You dont have enough wood\n";
    }
    return 0;
}

//Wood FUNTION<---------------------------------
int Wood(int iLevel, int iLevelCost, int iCharW, int iTime, int iWood, int iDays, int iDayTime)
{
    int iWoodChance = 0;
    int iChance = 0;
    int iCost = 0;
    iCost = 15 + iCharW + iLevelCost;
    iChance = iLevel - (iDays *5) + iCharW;
    iWoodChance= rand() % 100 + 1;
    if(iWoodChance <= iChance)
    {
        iWood = iWood + iWoodChance/5;
        iTime = iTime - iCost;
        iTime -= iCost;
    }
    else
    {
        iTime -= iCost;
        cout<<"You failed, no wood is found. Nubs.....\n";
    }
    return 0;
}

//Shelter FUNTION<---------------------------------
int Shelter(int iWood, int iLeaf, int iLevel, int iLevelCost, int iCharS, int iTime, int iShelter, int iDayTime, int iDays)
{
    int iShelterChance = 0;
    int iDayShelter = 0;
    int iChance = 0;
    int iCost = 0;
    if (iShelter == 0)
    {
        if (iWood >= 10 && iLeaf >= 10)
        {
            iCost = 50 + iCharS + iLevelCost;
            iChance = iLevel + (iDays *5) + iCharS;
            iShelterChance = rand() % 100 + 1;
            if(iShelter <= iChance)
            {
                iWood -= 10;
                iLeaf -=10;
                cout<<"You made a shelter";
                iTime -= iCost;
                iShelter = 1;
                iDayShelter = iDays + 3;
            }
            else
            {
                cout<<"You failed, no shelter was made, and you lost 10 wood and 10 leaves. Nubs.....\n";
            }
        }
        else
        {
            cout<<"You dont have enough wood or leaves, try again when you have 10 leaves and 10 wood\n";
        }
    }
    else
    {
    cout<< "You allreay have a shelter";
    }
    return 0;
}

//LEAF FUNCTION <------------------------------------------------------------
int Leaf(int iLevel, int iLevelCost, int iCharL, int iTime, int iLeaf, int iDayTime, int iDays)
{
    int iLeafChance = 0;
    int iChance = 0;
    int iCost = 0;
    iCost = 10 + iCharL + iLevelCost;
    iChance = iLevel - (iDays *5) + iCharL;
    iLeafChance = rand() % 100 + 1;
    if(iLeafChance <= iChance)
    {
        iLeaf = iLeafChance/5;
        iTime -= iCost;
    }
    else
    {
        cout<<"You failed, no leaves were found. Nubs.....\n";
    }
    return (iTime);
}
Last edited on
Second Part:

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
//Food FUNTION<---------------------------------
int Food(int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays)
{
	int iFoodChance = 0;
	int iChance = 0;
	int iCost = 0;
	iCost = 15 + iCharF + iLevelCost;
	iChance = iLevel - (iDays *5) + iCharF;
	iFoodChance= rand() % 100 + 1;
	if(iFoodChance <= iChance)
	{
		iFood = iFoodChance/5;
		iTime -= iCost;
	}
	else
	{
		cout<<"You failed, no food is found. Nubs.....\n";
	}
	return;// (int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays); <---- doesnt return the variabels
}

int _tmain(int argc, _TCHAR* argv[])
{
	//Remember to put in title <!@#!@%!@$@#!$@!%^!%^&*&%^(W#IUHAW^@&*$(#&@$~%^!@%!$~ERF
	white();
	cout << "WELCOME TO ";
	bred();
	cout << "LORD OF THE FLEAS\n";
	white();
	cout << "This is a Texted based RPG, that the developers were forced to make. \n We basically spent 2 weeks on the title screen, and a 48 hour session of coding on the weekend.";
	cout << " We also were to lazy to make a story, so we are taking the plot of 'Lord of the Flies' by William Golding. So basically your flying away from Britian to get away";
	cout << "from World War II, and your shot down and land on an island. Now you and other kids have to survive till you are rescued. ";
	cout << " In order to have the most success you must use knowledge from the book to win. This Game helps your mathmatics and critical thinking.\n\n";
	cout << "How skillful are you in the art of time wasting?\n";
	cout << "Type 1 - Noob, Type 2 - Normal, Type 3 - Leet.\n";
	cout << "Level : ";
	bgreen();
	cin >> iLevel;
	white();
	if (iLevel == 1)
	{
		iLevel = 50;
		iLevelCost = 20;
	}
	else if (iLevel == 2)
	{
		iLevel = 40;
		iLevelCost = 25;
	}
	else if (iLevel == 3)
	{
		iLevel = 30;
		iLevelCost = 30;
	}
	else
	{
		cout << "Noob";
	}
	Sleep(2000);
	Cls();
	cout << "Who would you like to be to tackle this stuff?\n";
	cout << "The stuff beisde each person is how it effects the cost for each action.\n";
	cout << "So lets say I was Ralph and I wanted to make a fire, and the base cost is 30, so the cost would be 15 for me to make a fire.\n\n";
	cout << "Type 1 - Ralph: Fire = -15, Wood = +15, Hunting = +20, Leaves = N/C, Shelter = -20\n";
	cout << "Type 2 - Jack: Fire = +25, Wood = -10, Hunting = -25, Leaves = +5, Shelter = +5\n";
	cout << "Type 3 - Piggy: Fire = -25, Wood = +20, Hunting = +35, Leaves = -10, Shelter = +20\n";
	cout << "Character : ";
	bblue();
	cin >> iChar;
	white();
	if (iChar == 1) //Ralph
	{
		iCharF -= 20;
		iCharW += 10;
		iCharH += 10;
		iCharL = 0;
		iCharS -= 20;
	}
	else if (iChar == 2) //Jack
	{
		iCharF += 25;
		iCharW -= 10;
		iCharH -= 15;
		iCharL += 5;
		iCharS += 5;
	}
	else if (iChar == 3) //Piggy
	{
		iCharF -= 40;
		iCharW += 20;
		iCharH += 20;
		iCharL -= 10;
		iCharS += 20;
	}
	else
	{
		cout << "Noob";
	}
	Sleep(2000);
	Cls();
	cout << "My guess is you know what health points are, so your health points are called time. You will have an action menu to choose what to do.";
	cout << " In order to survive you must keep warm, be fed and have water. It cost time to do actions. Good luck.";
	Sleep(2000);
	Cls();
        while (iRescue == 1)
	{
		cout << "What do you want to do? You have ";
		bpurple();
		cout << iTime;
		white();
		cout << " Time.\n";
		cout << "Type 1 to make a fire. (Lasts 1 day) (It will cost you 25 + Character + Level Cost)\n";
		cout << "Type 2 to look for wood. (It will cost you 15 + Character + Level Cost)\n";
		cout << "Type 3 to look for leaves. (It will cost you 5 + Character + Level Cost)\n";
		cout << "Type 4 to hunt for food. (It will cost you 5 + Character + Level Cost)\n";
		cout << "Type 5 to make a shelter. (It will cost you 40 + Character + Level Cost)\n";
		cout << "Type 6 to display information.\n";
		cin >> iMenu;
		if (iMenu == 1)
		{
			Fire(iWood, iLevel, iLevelCost, iCharF, iDays, iTime, iFire, iDayTime);
		}
		else if (iMenu == 2)
		{
			Wood(iLevel, iLevelCost, iCharW, iTime, iWood, iDays, iDayTime);
		}
		else if (iMenu == 3)
		{
			Leaf(iLevel, iLevelCost, iCharL, iTime, iLeaf, iDayTime, iDays);
		}
		else if (iMenu == 4)
		{
			Food(iLevel, iLevelCost, iCharF, iTime, iFood, iDayTime, iDays);
		}
		else if (iMenu == 5)
		{
			if(iDays == iDaysShelter)
			{
				iShelterMade = 0;
			}
			Shelter(iWood, iLeaf, iLevel, iLevelCost, iCharS, iTime, iShelter, iDayTime, iDays);
		}
		else if(iMenu == 6)
		{
			Display(iTime, iLevel, iLevelCost, iChar, iCharF, iCharW, iCharL, iCharH, iCharS, iDays, iDayTime, iFire, iShelter, iShelterMade, iDaysShelter, iLeaf, iWood, iFood);
		}
		else
		{
			cout << "idk";
		}
	}
	return 0;
}
can someone build this and tell me whats wrong, some return error is pissing me off and i dont know what to do btw thx for formatting babe
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include "windows.h"
#include "string"
#include <fstream>
#include <conio.h>
#include <mmsystem.h>

using namespace std;

// colours
void dblue() //dark blue function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 1);
return;
}
void dgreen() //dark green function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 2);
return;
}
void dcyan() //dark cyan function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 3);
return;
}
void dred() //dark red function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 4);
return;
}
void dpurple() //dark purple function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 5);
return;
}
void dyellow() //dark yellow function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 6);
return;
}
void white() //white function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 7);
return;
}
void grey() //grey function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 8);
return;
}
void bblue() //bright blue function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 9);
return;
}
void bgreen() //bright green function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 10);
return;
}
void bcyan() //bright cyan function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 11);
return;
}
void bred() //bright red function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 12);
return;
}
void bpurple() //bright purple function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 13);
return;
}
void byellow() //bright yellow function
{
HANDLE hColor;
hColor = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hColor, 14);
return;
}

int iRescue = 1;
int iTime = 500;

//Difficulty Integers
int iLevel = 0;
int iLevelCost = 0;

//Character integers (Stats and stuff)
int iChar = 0;
int iCharF = 0;
int iCharW = 0;
int iCharH = 0;
int iCharL = 0;
int iCharS = 0;

//Days Integer
int iDays = 1;
int iDayTime = 0;

//Menu Integer
int iMenu = 0;

//Action Integers
int iFire = 0;
int iShelter = 0;
int iShelterMade = 0;
int iDaysShelter = 0;
int iLeaf = 0;
int iWood = 0;
int iFood = 0;

void Display (int iTime, int iLevel, int iLevelCost, int iChar, int iCharF, int iCharW, int iCharL, int iCharH,
int iCharS, int iDays, int iDayTime, int iFire, int iShelter, int iShelterMade, int iDaysShelter,
int iLeaf, int iWood, int iFood)
{
cout << "You have "<< iTime << " Time left on the island.\n";
//Difficulty Integers
cout << "Your difficulty is level "<< iLevel << " and the cost of actions increase by " << iLevelCost <<".\n";
//Character integers (Stats and stuff)
cout << "Your Stats are :\n";
cout << "Fire making abilities : "<< iCharF << ".\n";
cout << "Wood wfinding abilities : "<< iCharW << ".\n";
cout << "Hunting abilities : "<< iCharH << ".\n";
cout << "Leave finding abilities : "<< iCharL << ".\n";
cout << "Shelter building abilities : "<< iCharS << ".\n";
//Days Integer
cout << "You have been on the island for "<< iDays << " days.\n";
//Action Integers
cout << "You have " << iFire << " fires.\n";
cout << "You have " << iWood << " pieces of wood.\n";
cout << "You have " << iShelter << " shelters, that have been up for " << iDaysShelter << " days.\n";
cout << "You have " << iFood << " pieces of food.\n";
cout << "You have " << iLeaf << " leaves.\n";
Sleep (7500);
return;
}//<------------------------ rescue function
int Died (int iLevel, int iDays, int iChar, int iTime, int iRescue)
{
int iFate;
int iChance = 0;
int iRescueChance = 0;
iFate= rand() % 10 + 1;
iChance = (iDays * 5) + (iChar * 50)- iLevel ;
iRescueChance= rand() % 100 + 1;
if (iRescueChance <= iChance)
{
iRescue = 0;
cout <<"You have been rescued\n";
while (iTime >= 500)
{
cout <<"You returned home safely\n";
Sleep (10000);
break;
}
while(iTime>=350)
{
cout <<"You are sent to the hospital\n";
if (iFate <=8)
{
cout <<"You go home healthy\n";
Sleep (10000);
}
else
{
cout <<"You have died\n";
Sleep (10000);
}
break;
}
while (iTime>= 250)
{
cout <<"You have been sent to the hospital\n";
if (iFate <= 5)
{
cout <<"You go home healthy\n";
Sleep (10000);
}
else
{
cout <<"You have died\n";
Sleep (10000);
}
break;
}
while (iTime<250)
{
cout<<"You have been sent to the hospital\n";
if (iFate <= 3)
{
cout<<"You go home healthy\n";
Sleep (10000);
}
else
{
cout<<"You have died\n";
Sleep (10000);
}
}
}
else
{
cout << "you were not saved\n";
Sleep(10000);
}
return 0;
}

//FIRE FUNTION<---------------------------------
int Fire(int iWood, int iLevel, int iLevelCost, int iCharF, int iDays, int iTime, int iFire, int iDayTime)
{
if (iWood >= 10)
{
int iChance = 0;
int iCost = 0;
iCost = 30 + iCharF + iLevelCost;
iChance = iLevel + (iDays *5) + iCharF;
iFire= rand() % 100 + 1;
iTime -= iCost;
if(iFire <= iChance)
{
iWood -= 10;
cout<<"You made a fire";
}
else
{
cout<<"You failed, no fire was made, and you lost 10 wood. Nubs.....\n";
}
}
else
{
cout<<"You dont have enough wood\n";
}
return 0;
}

//Wood FUNTION<---------------------------------
int Wood(int iLevel, int iLevelCost, int iCharW, int iTime, int iWood, int iDays, int iDayTime)
{
int iWoodChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 15 + iCharW + iLevelCost;
iChance = iLevel - (iDays *5) + iCharW;
iWoodChance= rand() % 100 + 1;
if(iWoodChance <= iChance)
{
iWood = iWood + iWoodChance/5;
iTime = iTime - iCost;
iTime -= iCost;
}
else
{
iTime -= iCost;
cout<<"You failed, no wood is found. Nubs.....\n";
}
return 0;
}

Last edited on
//Shelter FUNTION<---------------------------------
int Shelter(int iWood, int iLeaf, int iLevel, int iLevelCost, int iCharS, int iTime, int iShelter, int iDayTime, int iDays)
{
int iShelterChance = 0;
int iDayShelter = 0;
int iChance = 0;
int iCost = 0;
if (iShelter == 0)
{
if (iWood >= 10 && iLeaf >= 10)
{
iCost = 50 + iCharS + iLevelCost;
iChance = iLevel + (iDays *5) + iCharS;
iShelterChance = rand() % 100 + 1;
if(iShelter <= iChance)
{
iWood -= 10;
iLeaf -=10;
cout<<"You made a shelter";
iTime -= iCost;
iShelter = 1;
iDayShelter = iDays + 3;
}
else
{
cout<<"You failed, no shelter was made, and you lost 10 wood and 10 leaves. Nubs.....\n";
}
}
else
{
cout<<"You dont have enough wood or leaves, try again when you have 10 leaves and 10 wood\n";
}
}
else
{
cout<< "You allreay have a shelter";
}
return 0;
}

int Cls()//MADE BY DANIEL JUNG, TAKEN FROM HIS RPG LIFE PROGRAM (I TRIED BUT I QQ'D COULDN'T MAKE ONE #STANLEY==NOOB)
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Handle to stdout
// Gets the console resolution
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill every cell with spaces
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
// Fill the console attributes
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
// Sets the cursor position back to the first row and column
SetConsoleCursorPosition(hConsole, coordScreen);
system("CLS");
return 0;
}
//LEAF FUNCTION <------------------------------------------------------------
int Leaf(int iLevel, int iLevelCost, int iCharL, int iTime, int iLeaf, int iDayTime, int iDays)
{
int iLeafChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 10 + iCharL + iLevelCost;
iChance = iLevel - (iDays *5) + iCharL;
iLeafChance = rand() % 100 + 1;
if(iLeafChance <= iChance)
{
iLeaf = iLeafChance/5;
iTime -= iCost;
}
else
{
cout<<"You failed, no leaves were found. Nubs.....\n";
}
return (iTime);
}
//Food FUNTION<---------------------------------
int Food(int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays)
{
int iFoodChance = 0;
int iChance = 0;
int iCost = 0;
iCost = 15 + iCharF + iLevelCost;
iChance = iLevel - (iDays *5) + iCharF;
iFoodChance= rand() % 100 + 1;
if(iFoodChance <= iChance)
{
iFood = iFoodChance/5;
iTime -= iCost;
}
else
{
cout<<"You failed, no food is found. Nubs.....\n";
}
return ;// (int iLevel, int iLevelCost, int iCharF, int iTime, int iFood, int iDayTime, int iDays); <---- doesnt return the variabels
}

int _tmain(int argc, _TCHAR* argv[])
{
//Remember to put in title <!@#!@%!@$@#!$@!%^!%^&*&%^(W#IUHAW^@&*$(#&@$~%^!@%!$~ERF
white();
cout << "WELCOME TO ";
bred();
cout << "LORD OF THE FLEAS\n";
white();
cout << "This is a Texted based RPG, that the developers were forced to make. \n We basically spent 2 weeks on the title screen, and a 48 hour session of coding on the weekend.";
cout << " We also were to lazy to make a story, so we are taking the plot of 'Lord of the Flies' by William Golding. So basically your flying away from Britian to get away";
cout << "from World War II, and your shot down and land on an island. Now you and other kids have to survive till you are rescued. ";
cout << " In order to have the most success you must use knowledge from the book to win. This Game helps your mathmatics and critical thinking.\n\n";
cout << "How skillful are you in the art of time wasting?\n";
cout << "Type 1 - Noob, Type 2 - Normal, Type 3 - Leet.\n";
cout << "Level : ";
bgreen();
cin >> iLevel;
white();
if (iLevel == 1)
{
iLevel = 50;
iLevelCost = 20;
}
else if (iLevel == 2)
{
iLevel = 40;
iLevelCost = 25;
}
else if (iLevel == 3)
{
iLevel = 30;
iLevelCost = 30;
}
else
{
cout << "Noob";
}
Sleep(2000);
Cls();
cout << "Who would you like to be to tackle this stuff?\n";
cout << "The stuff beisde each person is how it effects the cost for each action.\n";
cout << "So lets say I was Ralph and I wanted to make a fire, and the base cost is 30, so the cost would be 15 for me to make a fire.\n\n";
cout << "Type 1 - Ralph: Fire = -15, Wood = +15, Hunting = +20, Leaves = N/C, Shelter = -20\n";
cout << "Type 2 - Jack: Fire = +25, Wood = -10, Hunting = -25, Leaves = +5, Shelter = +5\n";
cout << "Type 3 - Piggy: Fire = -25, Wood = +20, Hunting = +35, Leaves = -10, Shelter = +20\n";
cout << "Character : ";
bblue();
cin >> iChar;
white();
if (iChar == 1) //Ralph
{
iCharF -= 20;
iCharW += 10;
iCharH += 10;
iCharL = 0;
iCharS -= 20;
}
else if (iChar == 2) //Jack
{
iCharF += 25;
iCharW -= 10;
iCharH -= 15;
iCharL += 5;
iCharS += 5;
}
else if (iChar == 3) //Piggy
{
iCharF -= 40;
iCharW += 20;
iCharH += 20;
iCharL -= 10;
iCharS += 20;
}
else
{
cout << "Noob";
}
Sleep(2000);
Cls();
cout << "My guess is you know what health points are, so your health points are called time. You will have an action menu to choose what to do.";
cout << " In order to survive you must keep warm, be fed and have water. It cost time to do actions. Good luck.";
Sleep(2000);
Cls();
while (iRescue == 1)
{
cout << "What do you want to do? You have ";
bpurple();
cout << iTime;
white();
cout << " Time.\n";
cout << "Type 1 to make a fire. (Lasts 1 day) (It will cost you 25 + Character + Level Cost)\n";
cout << "Type 2 to look for wood. (It will cost you 15 + Character + Level Cost)\n";
cout << "Type 3 to look for leaves. (It will cost you 5 + Character + Level Cost)\n";
cout << "Type 4 to hunt for food. (It will cost you 5 + Character + Level Cost)\n";
cout << "Type 5 to make a shelter. (It will cost you 40 + Character + Level Cost)\n";
cout << "Type 6 to display information.\n";
cin >> iMenu;
if (iMenu == 1)
{
Fire(iWood, iLevel, iLevelCost, iCharF, iDays, iTime, iFire, iDayTime);
}
else if (iMenu == 2)
{
Wood(iLevel, iLevelCost, iCharW, iTime, iWood, iDays, iDayTime);
}
else if (iMenu == 3)
{
Leaf(iLevel, iLevelCost, iCharL, iTime, iLeaf, iDayTime, iDays);
}
else if (iMenu == 4)
{
Food(iLevel, iLevelCost, iCharF, iTime, iFood, iDayTime, iDays);
}
else if (iMenu == 5)
{
if(iDays == iDaysShelter)
{
iShelterMade = 0;
}
Shelter(iWood, iLeaf, iLevel, iLevelCost, iCharS, iTime, iShelter, iDayTime, iDays);
}
else if(iMenu == 6)
{
Display(iTime, iLevel, iLevelCost, iChar, iCharF, iCharW, iCharL, iCharH, iCharS, iDays, iDayTime, iFire, iShelter, iShelterMade, iDaysShelter, iLeaf, iWood, iFood);
}
else
{
cout << "idk";
}
}
return 0;
}
Topic archived. No new replies allowed.