#include<iostream.h>
#include<conio.h>

class suitcase
{
	int sno[20];
	long double amount[20];
	public:
	suitcase();

	void print()
	{
		int i;
		for(i=0;i<=19;i++)
		cout<<amount[i]<<'\n';
	}
};

suitcase::suitcase()
{

amount[20]={0.25,1.0,10.0,100.0,250.0,500.0,1000.0,5000.0,10000.0,50000.0,
100000.0,200000.0,300000.0,400000.0,500000.0,1000000.0,
2500000.0,5000000.0,7500000.0,10000000.0};


}

void main()
{
 suitcase s1;
 s1.print();

}

When I run this program, I get an error :-

expression syntax in function suitcase::suitcase()

Why am I getting an error? What am I doing wrong?

I know its a very stupid error, but can't spot which it is.

Kindly help me.

Thanks in advance.

You can't assign array elements like this:

amount[20]={0.25,1.0,10.0,100.0,250.0,500.0,1000.0,5000.0,10000.0,50000.0,
100000.0,200000.0,300000.0,400000.0,500000.0,1000000.0,
2500000.0,5000000.0,7500000.0,10000000.0};

Use following signature of main()

int main() {
     .......
     return 0;
 }

Ok...thanks.

I figured out the way of getting around this.

suitcase::suitcase()
{

		amount[0]=0.25;
		amount[1]=1;
		amount[2]=10;
		amount[3]=100;
		amount[4]=1000;
		amount[5]=5000;
		amount[6]=10000;
		amount[7]=25000;
		amount[8]=50000;
		amount[9]=75000;
		amount[10]=100000;
		amount[11]=200000;
		amount[12]=300000;
		amount[13]=400000;
		amount[14]=500000;
		amount[15]=1000000;
		amount[16]=2500000;
		amount[17]=5000000;
		amount[18]=7500000;
		amount[19]=10000000;
}

But this is too long a way. Isn't there any other way?

If you switch to standard C++ instead of an older version, you can use the STL vector class and initialize it with an array. The Boost library has a way of doing it directly to a vector without the array, and C++0x will add that into the language itself. But this works without Boost or waiting for the next standard to get implemented. It's a little shorter:

#include <iostream>
#include <vector>

using namespace std;

class suitcase
{
    vector<long double> amount;
public:
    suitcase();

    void print()
    {
        for (int i = 0; i < amount.size(); i++)
            cout << amount[i] << '\n';
    }
};

suitcase::suitcase()
{
    long double temp[20] =
    {
        0.25,1.0,10.0,100.0,250.0,500.0,1000.0,5000.0,10000.0,50000.0,
        100000.0,200000.0,300000.0,400000.0,500000.0,1000000.0,
        2500000.0,5000000.0,7500000.0,10000000.0
    };

    amount = vector<long double>(temp, temp + 20);
}

int main()
{
    suitcase s1;
    s1.print();
}

Yes, but the OP already stated in another thread, that he/she is forced to use turbo c++ at their school.

Ok, that's understandable. You can still do the same thing with a temporary array and an initializer, then a loop to assign the temporary array to the array field:

#include <iostream.h>

class suitcase
{
    long double amount[20];
public:
    suitcase();

    void print()
    {
        int i;

        for (i = 0; i < 20; i++)
            cout << amount[i] << '\n';
    }
};

suitcase::suitcase()
{
    long double temp[20] =
    {
    0.25,1.0,10.0,100.0,250.0,500.0,1000.0,5000.0,10000.0,50000.0,
        100000.0,200000.0,300000.0,400000.0,500000.0,1000000.0,
        2500000.0,5000000.0,7500000.0,10000000.0
    };
    int x;

    for (x = 0; x < 20; ++x)
        amount[x] = temp[x];
}

int main()
{
    suitcase s1;
    s1.print();
    return 0;
}
This question has already been answered. Start a new discussion instead.