Hammurabi game display message function

need help with this code 3 of the values are inputting in the wrong place, what am i doing wrong
it is outputting as:

1051001000120150020 //do not want this output
Hammurabi: I beg to report to you that in Year 1
0 people starved;
5 immigrants came to the city
the city population is 100
the city now owns 1000 acres
you harvested 10 bushels per acre //should be 2
rats ate 1500 bushels //should be 10
you now have 2 bushels in store //should be 1500
land is trading at 20 bushels per acre

press any key to continue.....

//Define a class Hammurabi with a member function that takes a parameter;
//Create a Hammurabi object and call its displayMessage function.
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

//Hammurabi class definition
class Hammurabi
{
public:
//function that displays a message to the Hammurabi user
//Print out the introductory message
void displayMessage (int year, int starved, int immigrants, int population, int land, int storage, int harvest, int rats, int trade)
{
cout << "Hammurabi: I beg to report to you that in Year " << year << endl;
cout << starved << " people starved;" << endl;
cout << immigrants << " immigrants came to the city" << endl;
cout << "The city population is " << population << endl;
cout << "The city now owns " << land << " acres" << endl;
cout << "You harvested " << harvest << " bushels per acre;" << endl;
cout << " Rats ate " << rats << " bushels;" << endl;
cout << "You now have " << storage << " bushels in store;" << endl;
cout << "Land is trading at " << trade << " bushels per acre" << endl;
cout << endl;
}//end function displayMessage
};//end class Hammurabi

//function main begins program execution
int main()
{
//variables to store the values
int year = 1;
int starved = 0;
const int immigrants = 5;
int population = 100;
int land = 1000;
const int harvest = 2;
const int rats = 10;
int storage = 1500;
const int trade = 20;

Hammurabi myHammurabi; //create a Hammurabi object named my Hammurabi

//input integer names
cout << year << starved << immigrants << population << land << harvest << rats << storage << trade << endl;

//call my Hammurabi displayMessage function
//and pass values as an argument
myHammurabi.displayMessage(year, starved, immigrants, population, land, harvest, rats, storage, trade);

system("pause");
return 0;
}//end main


ok sorted now changed a few things
closed account (30X1hbRD)
I commented out cout << year << starved << immigrants << population << land << harvest << rats << storage << trade << endl; and it got rid of the random numbers. and it seemed to still work properly
Last edited on
Topic archived. No new replies allowed.