PDA

View Full Version : Problem with array



marpis
12-05-2008, 01:37 PM
I'm making a program that calculates inflation in Finland.
the system is based on a cost-of-living index.
http://tilastokeskus.fi/til/khi/2008/10/khi_2008_10_2008-11-14_tau_002_en.html

Atm. there are only index datas of 2 years (1952 and 1953), so there are
2 rows in the array. I don't need 1951, so don't ask about it.

Im trying to run this script with Dev-C++, but it fails.
I can't figure out what's wrong, propably something with the array cause it only whines about those lines where the array i used (10 and 21)

I can clear this abit:
hnow = the price now
hbef = the price before
a1 = the year whose price i know
a2 = the year whose price i want to know
c = category = cell in the array


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int hnow, hbef, a1, a2, ind1, ind2, row, row2, c;

int index[2][12] {
{102, 101, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102 },
{102, 103, 103, 103, 103, 103, 103, 103, 103, 104, 103, 102 } };

//index before
cout << "The year whose prices i want to know is:" << endl;
cin >> a1;
row = a1 - 1952;
cout << "The category of the item is (0-11):" << endl;
cin >> c;

ind1 = index[row][c];
//index now
cout << "To which year you want the price to be inflated?" << endl;
cin >> a2;
row2 = a2 - 1952;

ind2 = index[row2][c];
cout << "What was the price in " << a1 <<" ?" << endl;
//request price before
cin >> hbef;
//calculation
hnow = (hbef / ind1) *ind2
cout << "In " << a2 << " the price SHOULD be: " << hnow << endl;
system("PAUSE");
return EXIT_SUCCESS;
}

A G E N T
12-05-2008, 09:10 PM
You were missing an equals sign and a semicolon.


#include <iostream>
#include <cstdlib>


using namespace std;

int main(int argc, char *argv[])
{
int hnow, hbef, a1, a2, ind1, ind2, row, row2, c;

int index[2][12] = {
{102, 101, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102 },
{102, 103, 103, 103, 103, 103, 103, 103, 103, 104, 103, 102 } };

//index before
cout << "The year whose prices i want to know is:" << endl;
cin >> a1;
row = a1 - 1952;
cout << "The category of the item is (0-11):" << endl;
cin >> c;

ind1 = index[row][c];
//index now
cout << "To which year you want the price to be inflated?" << endl;
cin >> a2;
row2 = a2 - 1952;

ind2 = index[row2][c];
cout << "What was the price in " << a1 <<" ?" << endl;
//request price before
cin >> hbef;
//calculation
hnow = (hbef / ind1) *ind2;
cout << "In " << a2 << " the price SHOULD be: " << hnow << endl;
system("PAUSE");
return EXIT_SUCCESS;
}