i can't compile my program :( :(

i don't know why i can't compile my program , help me the find out plz
here is the code

#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
class calcul
{
int nbval, x, *val;
public:
calcul(int,int);
~calcul();
void affiche();
};
calcul::calcul(int nb, int mul)
{
int i;
nbval = nb;
val = new int;
x = 0 ;
for(i=0;i<nbval;i++)
{
val[i] = i*mul;
x = x + val[i];
}
}
calcul::~calcul()
{ delete val;}
void calcul::affiche()
{
int i;
for(i=0;i<nbval;i++)
{
cout<<val[i]<<" ";
cout<<"\n";
}
cout<<"la somme des elements de la suite est :"<<x;

}
int main()
{
calcul suite1(6,4);
suite1.affiche();
calcul suite2(6,8);
suite2.affiche();
system("pause");
}
Last edited on
If you can't compile your program, then some sort of compilation error would have occurred. Common sense would tell you to post the error as well. I'm not looking at this until you do.
closed account (z05DSL3A)
38
39
40
41
42
43
44
45
int main()
{
    calcul suite1(6,4);
    suite1.affiche();
    calcul suite2(6,;  /* Here */
    suite2.affiche();
    system("pause");
}
here is a picture explain everything

http://img593.imageshack.us/img593/765/erri.jpg
@ grey Wolf :
its not that my friend i just didn't paste the right code , ill edit it right now
Take a look at the code below. you have val = new int;. And then you are attempting to access individual elements of an array called val in your for loop. val[i] = i*mul; as well as other places. But you never correctly created a new array for val. It should of been val = new int[some number];

1
2
3
4
5
6
7
8
9
10
11
12
13
calcul::calcul(int nb, int mul)
{
int i;
nbval = nb;
val = new int;
x = 0 ;
for(i=0;i<nbval;i++)
{
val[i] = i*mul;
x = x + val[i];
}
}
calcul::~cal
@Return 0 : thnx so much , its solved
Topic archived. No new replies allowed.