Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translating A Program from 6.0 to 4.0

Status
Not open for further replies.

SpeakerForTheDead

Programmer
Jan 31, 2002
28
0
0
US
Okay. I have version 6.0 at school and 4.0 at home. I brought home a program, fixed the obvious translations (getting rid of "using namespace std;" and adding ".h" to everything) yet it STILL has 36 errors and 15 warnings. I think it's a problem with my string variables. Do I have to include an additional library in order to use "string"?
 
Here's the code:


//A game where you manage a bar, buying and selling drinks, NOW you can save your game!
//Created by Gilad "Speaker For The Dead" Barlev
//Final Programming Edit on 16/1/02 (D/M/Y)
//Final Internal Documentation Edit on 15/1/02 (D/M/Y)

#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
//using namespace std;

//function prototypes
int calcPrice (int);
float buyDrink(int, float);
float setPrice(int, int, string);
int sellDrink(string, int, int, float);
void clrScr();

int main ()
{//main function

//declare variables
int x = 0;
char y = ' ';
float dollars = float(100);
int beerQty = 10;
int wineQty = 10;
int martiniQty = 10;
int vodkaQty = 10;
int whiskeyQty = 10;
int beerWhole = 0;
int wineWhole = 0;
int martiniWhole = 0;
int vodkaWhole = 0;
int whiskeyWhole = 0;
int beerPaco = 0;
int winePaco = 0;
int martiniPaco = 0;
int vodkaPaco = 0;
int whiskeyPaco = 0;
float beerPrice = 0.0;
float winePrice = 0.0;
float martiniPrice = 0.0;
float vodkaPrice = 0.0;
float whiskeyPrice = 0.0;
int beerSold = 0;
int wineSold = 0;
int martiniSold = 0;
int vodkaSold = 0;
int whiskeySold = 0;
float earnings = 0.0;
int event = 0;
int day = 0;

//initialze random number generator
srand (time (NULL));

//intro
cout << &quot;Speaker For The Dead Presents...&quot; << endl << endl;
getch ();

//Game Intro
cout << &quot; @@@@@@ &quot; << endl
<< &quot; @ 0 0 @ &quot; << endl
<< &quot; @ @ &quot; << endl
<< &quot; @ V @ &quot; << endl
<< &quot; @@@@@@ &quot; << endl
<< &quot; @@ &quot; << endl
<< &quot; @@@@ &quot; << endl
<< &quot; @ @@ @ &quot; << endl
<< &quot; ------------------------&quot; << endl
<< &quot; [ ## # * %%%% ]&quot; << endl
<< &quot; [ # # # * % ]&quot; << endl
<< &quot; [ #### # %%%% ]&quot; << endl
<< &quot; [ # # # % ]&quot; << endl
<< &quot; [ # # ##### %%%% ]&quot; << endl
<< &quot; [ ]&quot; << endl
<< &quot; [ TREETOP TAVERN ]&quot; << endl;
getch ();
cout << endl << &quot;'Hello, I'm AL!'&quot; << endl;
getch();
cout << endl << &quot;'How would you like to take&quot; << endl << &quot;over my tavern for a week?'&quot; << endl;
getch();
clrScr();

Main:
//main menu
cout << &quot;AL'S TREETOP TAVERN v1.0&quot; << endl << &quot;(1) Instructions&quot; << endl << &quot;(2) Main Game&quot; << endl << &quot;(3) Quit&quot; << endl;
cin >> x;
if (x != 1 && x != 2)
{//quit
goto Credits;
}//end quit

if (x == 1)
{//instructions
cout << endl << endl << endl << &quot;Here are AL's instructions:&quot; << endl << endl;
getch ();
cout << &quot; ______________________________________________________&quot; << endl
<< &quot;[You'll be managing my tavern for a week, ]&quot; << endl
<< &quot;[buying and selling booze. ]&quot; << endl
<< &quot;[while competing with Paco's tavern down the road. ]&quot; << endl
<< &quot;[Your goal is to rake up as much dough as you can. ]&quot; << endl
<< &quot;[Remember: ]&quot; << endl
<< &quot;[ People will not buy booze from you if they can ]&quot; << endl
<< &quot;[get it somewhere else for a lesser price. ]&quot; << endl
<< &quot;[ ]&quot; << endl
<< &quot;[Bye! ]&quot; << endl
<< &quot;[______________________________________________________]&quot; << endl;
goto Main;
}//end instructions
if (x == 2)
{//game
//declare fstream commands
ifstream fin;
ofstream fout;

//load game
string file;
cout << &quot;Enter name of new or previous game:&quot; << endl;
cin >> file;
fin.open(file.c_str());
if (!fin.is_open() )
{//create new game
cout << &quot;File not fount. Creating new file...&quot; << endl;
}//end create new game
else
{//load game
fin >> day;
fin >> dollars;
fin >> beerQty;
fin >> wineQty;
fin >> martiniQty;
fin >> vodkaQty;
fin >> whiskeyQty;
}//end load game

while (day < 7)
{//day loop
day = day + 1;

//calculate prices
beerWhole = calcPrice(1);
wineWhole = calcPrice(2);
martiniWhole = calcPrice(4);
vodkaWhole = calcPrice(5);
whiskeyWhole = calcPrice(6);
beerPaco = calcPrice(2);
winePaco = calcPrice(3);
martiniPaco = calcPrice(5);
vodkaPaco = calcPrice(6);
whiskeyPaco = calcPrice(7);
getch();

//event creator
event = 1 + rand () % (3);

if (event == 1)
{//event selector
clrScr();
event = 1 + rand () % (7);
if (event == 1 || event == 2)
{//paco goes mad
cout << endl << &quot;Paco goes mad!&quot; << endl << &quot;He raises prices to the point of insanity!&quot; << endl;
beerPaco = 9;
winePaco = 9;
martiniPaco = 9;
vodkaPaco = 9;
whiskeyPaco = 9;
}//end paco's madness
if (event == 3 || event == 4)
{//vodka confiscated
cout << endl << &quot;Health Inspectors confiscate your Vodka&quot; << endl;
vodkaQty = 0;
}//end of confiscation
if (event == 5 || event == 6)
{//new brewry
cout << endl << &quot;New Local Brewry!&quot; << endl << &quot;Wholesale Prices Plummet!!!&quot; << endl;
beerWhole = 1;
wineWhole = 1;
martiniWhole = 3;
vodkaWhole = 4;
whiskeyWhole = 5;
}//end brewry
if (event == 7)
{//robbery
cout << endl << &quot;A man in a donkey-suit holds up your store&quot; << endl << &quot;and steals ALL YOUR MONEY!&quot; << endl;
dollars = 0;
}//end robbery
getch();
}//end event selector


Game:
//main game menu
clrScr();
cout << endl << endl << &quot;AL'S TREETOP TAVERN - DAY &quot; << day << endl << &quot;(1)Buy Drinks&quot; << endl << &quot;(2)Compare Prices&quot; << endl << &quot;(3)Check Stocks&quot; << endl << &quot;(4)OPEN SHOP&quot; << endl << &quot;(5)Quit&quot; << endl << endl << &quot;Enter selection=? &quot;;
cin >> x;
if (x != 1 && x != 2 && x != 3 && x != 4)
{//quit
goto Credits;
}//end quit
if (x == 1)
{//buy drinks
cout << endl << &quot;BUY DRINKS - DAY &quot; << day << endl << &quot;(1)Beer $&quot; << beerWhole << endl << &quot;(2)Wine $&quot; << wineWhole << endl << &quot;(3)Martini $&quot; << martiniWhole << endl << &quot;(4)Vodka $&quot; << vodkaWhole << endl << &quot;(5)Whiskey $&quot; << whiskeyWhole << endl << &quot;Enter selection=?&quot;;
cin >> x;
if (x == 1)
{//buy beer
cout << endl << &quot;BEER:&quot; << endl;
x = buyDrink(beerWhole, dollars);
dollars = dollars - (beerWhole * x);
beerQty = beerQty + x;
goto Game;
}//end buy beer
if (x ==2)
{//buy wine
cout << endl << &quot;WINE:&quot; << endl;
x = buyDrink(wineWhole, dollars);
dollars = dollars - (wineWhole * x);
wineQty = wineQty + x;
goto Game;
}//end buy wine
if (x == 3)
{//buy martini
cout << endl << &quot;MARTINI:&quot; << endl;
x = buyDrink(martiniWhole, dollars);
dollars = dollars - (martiniWhole * x);
martiniQty = martiniQty + x;
goto Game;
}//end buy martini
if (x == 4)
{//buy vodka
cout << endl << &quot;VODKA:&quot; << endl;
x = buyDrink(vodkaWhole, dollars);
dollars = dollars - (vodkaWhole * x);
vodkaQty = vodkaQty + x;
goto Game;
}//end buy vodka
if (x == 5)
{//buy whiskey
cout << endl << &quot;WHISKEY:&quot; << endl;
x = buyDrink(whiskeyWhole, dollars);
dollars = dollars - (whiskeyWhole * x);
whiskeyQty = whiskeyQty + x;
goto Game;
}//end buy whiskey
goto Game;
}//end buy drinks
if (x == 2)
{//paco's prices
cout << endl << endl << &quot;PACO'S PRICES - DAY &quot; << day << endl << &quot;Beer $&quot; << beerPaco << endl << &quot;Wine $&quot; << winePaco << endl << &quot;Martini $&quot; << martiniPaco << endl << &quot;Vodka $&quot; << vodkaPaco << endl << &quot;Whiskey $&quot; << whiskeyPaco << endl << endl << &quot;Press any key to continue&quot; << endl;
getch();
goto Game;
}//end paco's prices
if (x == 3)
{//check stocks
cout << endl << endl << &quot;STOCKS - DAY &quot; << day << endl << &quot;Beer: &quot; << beerQty << endl << &quot;Wine: &quot; << wineQty << endl << &quot;Martini: &quot; << martiniQty << endl << &quot;Vodka: &quot; << vodkaQty << endl << &quot;Whiskey: &quot; << whiskeyQty << endl << endl << &quot;Press any key to continue&quot; << endl;
getch();
goto Game;
}//end check stocks
if (x == 4)
{//open shop
cout << &quot;Are you sure (Y/N)? &quot;;
cin >> y;
if (y != 'y' && y != 'Y')
{//cancel open shop
goto Game;
}//end cancel

//set selling prices
clrScr();
cout << endl << endl << endl << &quot;SET SELLING PRICES - DAY &quot; << day << endl;
beerPrice = setPrice(beerWhole, beerPaco, &quot;BEER&quot;);
winePrice = setPrice(wineWhole, winePaco, &quot;WINE&quot;);
martiniPrice = setPrice(martiniWhole, martiniPaco, &quot;MARTINI&quot;);
vodkaPrice = setPrice(vodkaWhole, vodkaPaco, &quot;VODKA&quot;);
whiskeyPrice = setPrice(whiskeyWhole, whiskeyPaco, &quot;WHISKEY&quot;);
}//end open shop
clrScr();

//day's results
cout << &quot;DAY &quot; << day << endl;
getch();
earnings = 0;
beerSold = sellDrink(&quot;Beer&quot;, beerQty, beerPaco, beerPrice);
beerQty = beerQty - beerSold;
earnings = beerSold * beerPrice + earnings;
wineSold = sellDrink(&quot;Wine&quot;, wineQty, winePaco, winePrice);
wineQty = wineQty - wineSold;
earnings = wineSold * winePrice + earnings;
martiniSold = sellDrink(&quot;Martini&quot;, martiniQty, martiniPaco, martiniPrice);
martiniQty = martiniQty - martiniSold;
earnings = martiniSold * martiniPrice + earnings;
vodkaSold = sellDrink(&quot;Vodka&quot;, vodkaQty, vodkaPaco, vodkaPrice);
vodkaQty = vodkaQty - vodkaSold;
earnings = vodkaSold * vodkaPrice + earnings;
whiskeySold = sellDrink(&quot;Whiskey&quot;, whiskeyQty, whiskeyPaco, whiskeyPrice);
whiskeyQty = whiskeyQty - whiskeySold;
earnings = whiskeySold * whiskeyPrice + earnings;
getch();
cout << &quot;Total Earnings: $&quot; << earnings << endl;
dollars = dollars + earnings;

//save game
fout.open(file.c_str());
fout << day << endl;
fout << dollars << endl;
fout << beerQty << endl;
fout << wineQty << endl;
fout << martiniQty << endl;
fout << vodkaQty << endl;
fout << whiskeyQty << endl;
fout.close();
cout << &quot;GAME SAVED.&quot; << endl;

}//end day loop
fin.close();
}//end game
//conclusion
clrScr();
cout << &quot; @@@@@@ &quot; << endl
<< &quot; @ 0 0 @ &quot; << endl
<< &quot; @ @ &quot; << endl
<< &quot; @ V @ &quot; << endl
<< &quot; @@@@@@ &quot; << endl
<< &quot; @@ &quot; << endl
<< &quot; @@@@ &quot; << endl
<< &quot; @ @@ @ &quot; << endl
<< &quot; ------------------------&quot; << endl
<< &quot; [ ## # * %%%% ]&quot; << endl
<< &quot; [ # # # * % ]&quot; << endl
<< &quot; [ #### # %%%% ]&quot; << endl
<< &quot; [ # # # % ]&quot; << endl
<< &quot; [ # # ##### %%%% ]&quot; << endl
<< &quot; [ ]&quot; << endl
<< &quot; [ TREETOP TAVERN ]&quot; << endl;
getch ();
cout << endl << &quot;'Hey! I'm back!'&quot; << endl;
getch ();
cout << endl << &quot;'How much money didja make?'&quot; << endl << endl << &quot;$&quot; << dollars << endl;
getch ();
if (dollars < 100)
{//pathetic
cout << endl << &quot;'You made me LOSE money! Get out, punk!'&quot; << endl;
}//end pathetic
if (dollars >= 100 && dollars < 200)
{//bad
cout << endl << &quot;'You barely made me ANY money! Get out, punk!'&quot; << endl;
}//end bad
if (dollars >= 200 && dollars < 500)
{//not bad
cout << endl << &quot;'Not bad for a beginner.'&quot; << endl;
}//end not bad
if (dollars >=500 && dollars < 1000)
{//thanks
cout << endl << &quot;'Thanks! Wanna free beer? Too bad!'&quot; << endl;
}//end thanks
if (dollars > 1000)
{//whoah
cout << endl << &quot;'Whoah! How'd you like to WORK here?'&quot; << endl << &quot;'How 'bout when you turn 21?'&quot; << endl;
}//end whoah
getch();


Credits:
//credits
clrScr();
cout << &quot;This program was made by Speaker For The Dead for entertainment purposes only.&quot; << endl << &quot;For problems with this program or more information on Speaker For The Dead,&quot; << endl<< &quot;Please send an email to the_sftd@yahoo.com&quot; << endl;
return 0;
}//end of main function

/*****PROGRAM DEFINED FUNCTIONS*****/
int calcPrice(int min)
{//random price creator
return min + rand() % (3);
}//end of price creator

float buyDrink(int price, float dollars)
{//drink buyer
int y = -1;
cout << &quot;$&quot; << price << &quot; a jug&quot; << endl << &quot;You have $&quot; << dollars << endl;
while (y < 0 || y * price > dollars)
{//purchase ammount
cout << &quot;How much ya gonaa buy? &quot;;
cin >> y;
}//end purchase ammount
return y;
}//end of drink buyer

float setPrice(int whole, int paco, string drink)
{//selling-price setter
float price = 0.0;
cout << endl << endl << drink << endl << &quot;Wholesale Price $&quot; << whole << endl << &quot;Paco's Price $&quot; << paco << endl << &quot;Your price $&quot;;
cin >> price;
return price;
}//selling-price setter

void clrScr()
{//clear screen function
int x = 0;
while (x < 25)
{//clrscreen
cout << endl;
x = x + 1;
}//end clrscreen
}//end clear screen

int sellDrink(string drink, int qty, int paco, float price)
{//drink seller
int x = 0;
int sold = 0;
int y = 0;
int z = 0;
cout << drink << &quot; sold: &quot;;
if (paco > price)
{
y = 10;
}
if (paco == price)
{
y = 5;
}
if (paco < price)
{
y = 0;
}
while (x < y && qty > 0)
{//selling loop
z = 0 + rand() % (2);
qty = qty - z;
sold = sold + z;
x = x + 1;
}//end selling loop
cout << sold << endl << drink << &quot; remaining: &quot; << qty << endl;
return sold;
}//end drink seller



//This program was made by Speaker For The Dead for entertainment purposes only.
//For problems with this program or more information on Speaker For The Dead,
//Please send an email to the_sftd@yahoo.com
 
Alright. I'm at school. string and string.h are two COMPLETELY different header files. My home computer doesn't have string (tho I suppose I could take it home). So that's probably the problem. Does ANYONE know what header files I'd need to do the same thing as &quot;string&quot;?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top