I was playing with the code for a little while.I figured out that I was missing a part of the code.
Nation::Nation(lName)
was not there yet.I also had to put a else in one of the statements.I guess I should just show you.
conquest.h
#include <stdio.h>#include<iostream>#include <string>using namespace std;//handles each nations for each playerclass Nation{//Member Declarationspublic:int land;int troops;private:string name;int food;int gold;int people;int farmers;int merchants;int blacksmiths;public:Nation(string lName);Nation();bool takeTurn(void);private:void menu(void);};//Create two nation objectsNation nation1;Nation nation2;//sets the default nation valuesNation::Nation(string lName){//this was a initialiser list but I had to change it to this //because of all the errors I was getting string name = lName; int land=20 ; int food=50 ; int troops=15; int gold=100; int people=100; int farmers = 0;int merchants = 0;int blacksmiths = 0;}//a default constructorNation::Nation(){}//takes a turn for the playerbool Nation::takeTurn(){cout <<"It's now " <<name <<"'s turn. \n";people += land * 0.2;food += farmers - people * 0.25;gold += merchants * 20;troops += blacksmiths;menu();if (nation1.land <= 0 || nation2.land <= 0) return false; elsereturn true;}//displays and handles the menu optionsvoid Nation::menu(){while (true){int input = 0;cout <<"food " <<food <<endl;cout <<"gold " <<gold <<endl;cout <<"land " <<land <<endl;cout <<"merchants " <<merchants <<endl<<"troops " <<troops <<endl<<"unemployed " <<people <<endl;cout <<"1) Buy Land \n"<<"2) Hire Farmers \n"<<"3) Hire Merchants \n"<<"4) Hire Weaponsmiths \n"<<"5) Attack!! \n"<<"6) Take Turn \n";cin >> input;switch(input){case 1: //Buys Landcout <<"You buy " <<gold/20 <<" sections of land.\n";land += gold/20;gold %= 20;cout <<"You now have " <<gold <<" gold.\n";break;case 2: //Hires Farmersfarmers += people;cout <<"You hired " <<people <<" farmers. \n";break;case 3: //Hires Merchantsmerchants += people;cout <<"You hired " <<people <<" merchants. \n";people = 0;break;case 4: //Hires Blacksmithsblacksmiths += people;cout <<" You Hired " <<people <<" blacksmiths. \n";people = 0;break;case 5: //Handles the Battlecout <<"The war wages into the night and all die!\n";if(nation1.troops <nation2.troops){nation2.land += 10;nation1.land += 10;}else if(nation1.troops > nation2.troops){nation2.land -= 10;nation2.land += 10;}nation1.troops = 0 ;//War is a bloody thingnation2.troops = 0; //Very Bloody indeedbreak;case 6: return; //ends the turn}}}
conquest.cpp
#include<string>#include "conquest.h"#include <stdio.h>//The main Game functionint main(void){string tempString;cout <<"Welcome to the Conquest \n";cout <<"What is your name player 1?\n";cin >> tempString;nation1 = Nation(tempString);cout <<"What is your name Player 2?\n";cin >> tempString;nation2 = Nation(tempString);while (nation1.takeTurn() && nation2.takeTurn()){}system("pause");return 0;}
It does compile without error but the problem is this gets me some really funky looking numbers so I can't understand what's going on in the program.Is this because of the warning??