Hello, I am trying to make an rpg, and I am having troubles with functions. I am currently working on the 'potion' aspect of my rpg, which I have highlighted in red.
My question is this: Is it possible to make the function return money, potion number, potion size, etc? I really need all of that data to be transferred into the main function. HELP!
*I will try to pay back the favor to the best of my ability. :)*
/* Game Created by Jacob Caron. Started on 11/2/09 */
//header declarations
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <iomanip>
#include <string>
#include <time.h>
#include <windows.h>
using namespace std;
//used to maximize screen
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
//initializing functions
void level2();
void level3();
int medic(int money);
//main function
int main()
{
//tells screen to maximize
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd,SW_MAXIMIZE);
/*****array declarations*****/
//armor
int armorcost[9] = {4, 9, 15, 22, 30, 39, 49, 60, 72};
char armorname[9][25] = {"Shirt", "Fur", "Leather", "Studded Leather", "Chain Mail", "Scale Mail", "Plate Mail", "Spiked Plate Mail", "Berzerker Aromor"};
int armorstrength[9] = {2, 7, 13, 20, 27, 35, 44, 54, 65};
//weapons
int weaponcost[9] = {9, 14, 20, 27, 35, 44, 54, 65, 77};
char weaponname[9][25] = {"Dagger", "Club", "Axe", "Short Sword", "Cutlass", "Bastard Sword", "Long Sword", "Great Sword", "Excaliber"};
int weaponstrength[9] = {7, 12, 18, 25, 32, 40, 49, 59, 70};
//menu array
char menu[5][25] = {"Visit the town medic", "Visit the Weapon Smith", "Go to the Armory", "Go to the trail", "View Stats"};
//counter
int count1;
//name
string name;
//money
int money = 10;
/*****Introduction*****/
cout << "Please Enter your name (One Word): ";
cin >> name;
system("cls");
cout << "Welcome to Grundor, " << name << ", the village were you were born.\n"
<< "Your mother, Marlene was abducted by the Horrid Dragon, Helsmich, in the land \n"
<< "of fire. In order for you to save your mother, you must travel along the \n"
<< "twisted trail into lands that are filled with terror. I bid you the best of \n"
<< "luck, and here is $10 to spend on supplies. I know it is not much, but I am \n"
<< "not the wealthiest man alive!\n\n";
system("pause");
system("cls");
/*****Main Menu*****/
//ask what user wants to do
cout << "What would you like to do?\n\n";
for(count1=0;count1<5;count1++)
cout << count1+1 << ". " << menu[count1] << endl;
cout << endl << ">> ";
cout << money;
cin >> count1;
system("cls");
//switch to change main event
switch(count1)
{
case 1:
medic(money);
break;
}
}
/*****Menu Options*****/
int medic(int money)
{
/*****Visiting the Medic*****/
//potions
char potionname[5][25] = {"Small Tonic", "Medium Tonic", "Large Tonic", "Grand Tonic", "Godly Tonic"};
int potioncost[5] = {5, 10, 15, 20, 30};
int potioneffect[5] = {5, 10, 20, 40, 100};
int potionsize[5] = {0, 0, 0, 0, 0};
system("cls");
cout << "Welcome to the Medic, what can I do you for?\n" << endl;
int x=0;
for(x;x<5;x++)
cout << x+1 << ". " << potionname[x] << " - " << potioncost[x] << endl;
cout << "\n>> ";
cin >> x;
system("cls");
money = money - potioncost[x-1];
potionsize[x-1] = potionsize[x-1] + 1;
cout << "You have succesfully purchased a " << potionname[x-1] << "!\n"
<< "You have lost " << potioncost[x-1] << " dollars!\n"
<< "You now have " << money << " dollars.\n\n";
cout << "----------------------------\n"
<< "You have: \n";
for(x=0;x<5;x++)
cout << potionsize[x] << " " << potionname[x] << "(s)" << endl;
cout << "----------------------------\n\n";
system("pause");
system("cls");
cout << "Would you like to buy more?\n\n";
cout << "1. yes\n2. no\n\n>> ";
cin >> x;
switch(x)
{
case 1:
medic(money);
break;
case 2:
main();
break;
}
}
//Other Functions
void level2()
{
cout << "As you look around the trail, you see a fox tearing apart a corpse in the dirt." << endl
<< "As you try to shoo away the fox it turns on you, and acts aggrssivly.\nPrepare for battle!\n\n";
}