well I was wondering if I was doing everything right, can you do this: variable[class[x].er], if not then I know where some errors are coming from..
During comp. sci. I thought up a good way to make a game where you own a buisness, txt based, but I figured if I made it then I'd learn some more about OOP. It's not that I don't know OOP it's that I've ben coding structured for ever.
Some of the variables are unused at this point but there going to be used later. I know this is rudundent but I figured on having the program compleate by tomowrow. But I don't wan't to continue with this many errors!
Code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
class mn; //main class
class store //holds each stor's values
{
int l, security, size, ad; //location, .., advertisment/popularity
float h;
public:
store();
};
store::store()
{
security = 1;
size = 1;
ad = 1;
}
class mn
{
double m, mm, buildc, addc, emwadge[3];//money, last turn money, c=cost
int numemployed[3], numstores; //em = emploey - num = number
double crime[4], cost[4], p[4]; //..., cost to build, population
double tax[4];
char ls[4]; //string.. this variable gives me troubles farther down
public:
mn();
int ats();
int bs();
//int a();
//int h();
int c();
};
mn::mn()
{
m = 50000.00;
buildc = 10000;
addc = 10000; //add - aditions.. cost salsmen, system admen
emwadge[0] = 7; emwadge[1] = 10; emwadge[2] = 15;//maniger
numemployed[0] = 0; numemployed[1] = 0; numemployed[2] = 0;
numstores = 0;
//the folowing lines are giving errors: invalid conversion from...
crime[0] = 2; cost[0] = 1; tax[0] = 1.06; ls[0] = "Charleston(WV)";
p[0] = 30;
crime[1] = 5; cost[1] = 2.5; tax[1] = 1.08; ls[1] = "Chicago"; p[1] = 60;
crime[2] = 7; cost[2] = 5; tax[2] = 1.15; ls[2] = "New Yourk"; p[2] = 100;
crime[3] = 10; cost[3] = 4; tax[3] = 1.1; ls[3] = "Los Angelas"; p[3] = 100;
//I'm aware these figure aren't acurate, I'll do research later
store store[9];
}
int mn::ats()//add on - make the store bigger
{
if (numstores == 0){
cout <<"No stores yet/n"; return 0;}
int x, xx;
cout <<"/nCost: "<<addc<<"/nWhich one?/n";
for (x = 1; x <= numstores; x++)
{
cout <<"Store "<<x <<"is "<<store[x-1].size <<" big and is located "
<<store[x-1].ls <<endl; //parse error before '[' token
}
cin >> x;
if (x > numstores){
cout <<"Store doesn't exist/n"; return 0;}
if (store[x].size >15){ //parse error before '[' token
cout <<"Sore too big/n"; return 0;}
cout <<"How much?/n"; //global scope: sytax error before '<<' token
cin >> xx; //global scope: sytax error before '<<' token
if (xx * addc * tax[store[x].l] > m){
cout <<"Not Enough Money/n"; return 0;}
store[x].size += xx;
m -= xx * addc * tax[store[x].l;//global scope: sytax error before '-=' token
numemployed[0] += xx * 2;//global scope: sytax error before '+=' token
numemployed[1] += xx;//global scope: sytax error before '+=' token
if (store[x].size == 5)
numemployed[2]++;
if (store[x].size == 10)
numemployed[2]++;
if (store[x].size == 15)
numemployed[2]++;
return 0;
}
int mn::bs()//build new store
{
int x;
cout <<"Where?/n";
for (x = 0; x < 4; x++)
{
cout <<ls[x] <<" " <<x <<"- Crime: "<<crime[x] <<" Cost: "
<<cost[x] * buildc <<" Tax: "<< tax[x] <<endl;
}
cin >> x;
if (x > 3){
cout <<"Location doesn't exist/n"; return 0;}
if (cost[x] * buildc > m){
cout <<"Not enough money/n"; return 0;}
numstores++;
store[numstores].l = x;//parse error before '[' token
m -= cost[x] * buildc;
numemployed[0] += 3;
numemployed[1] += 1;
numemployed[2] += 1;
}
/*int mn::a()
{
}*/
int mn::c()//calculates profits and such
{
mm = m;
if (numstores == 0)
return 0;
float r1;
srand(time(0));
r1 = 1+rand() %80;
int x;
for (x = 0; x < 3; x++)
m -= emwadge[x] * numemployed[x];
for (x = 0; x < numstores + 1; x++)
m -= store[x].size * 2000 * tax[store[x].l] * cost[store[x].l];//parse [
for (x = 0; x < numstores + 1; x++)
m += r1 * store[x].ad * p[store[x].l] * store[x].size;//pase before [
}
int main()
{
int choice = 0;//choice is initialized!!
mn mn;
while(1)
{
system("CLS");
cout <<mm<<endl;//previous balence
cout <<m <<endl <<endl;//curent balence
cout <<"(1)Add to store, (2)Build Store, (3)Advertise, (4)Continue/n";
cin >> choice; //choice undeclared..
if (choice == 1)
mn.ats();//parse error before ';'
else{
if (choice == 2)
mn.bs();
else{
//if (choice == 3)
//mn.a();
else{
//if (choice == 4)
//mn.h();
else
mn.c();}}}//parse error before '}'
}
}
The errors are marked, it should be just a couple lines causing all my problems, then one method of doing somethign: asigning a char a string..