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;
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.
Take a look at the code below. you have val = newint;. 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 = newint[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 = newint;
x = 0 ;
for(i=0;i<nbval;i++)
{
val[i] = i*mul;
x = x + val[i];
}
}
calcul::~cal