Because your variable sum is uninitialized, meaning it's value is garbage.
So when you do this sum*=data[i].num; which is short for sum = sum * data[i].num; It's like doing garbage equals to garbage times a number, which for obvious reasons doesnt work.
You can't initialize it to 0 because then everything will be 0 because anything times 0 is 0. So initialize it to 1.
data[counter].num is different than counter.
In your multiply()'s for statement, counter is ==0, so it doesn't need to run.
Same as in the getnumber() function, you do counter++. If the point of that is to get to the next array element, then it's correct, but otherwise, nope.
If you look at the for-loop it is 0. "i" starts at 0, what are you talking about? I ran his program with the fixes I suggested and it worked perfectly fine.
hey guys
one more problem
it works for add and multiply and it has some problem for minus and divide
i dont know how should i initialize sum for minus and divide
For add and minus, they should be initialized to 0. You should never use a variable that is not initialized.
When it comes to divide it is a bit more complex, and I think that is because of the actual design of this assignment. It needs some work. But you can solve the problem by doing this -
1 2 3 4 5 6 7 8 9 10 11 12
void Divide(){
float sum = (float)data[0].num; // initialize sum to the first number inside the array
for(int i=0;i<counter - 1;i++){ // run through the array but skip the first value (the first value is inside of sum)
sum/=data[i+1].num; // do the division starting from the second value in the array.
}
cout<<"sum is: "<<sum;
getch();
}