#include <iostream>
usingnamespace std;
int main ()
{
int i,n;
float sum, avg;
float *p;
cout << "How many marks you like to enter: ";
cin >> i;
p = newfloat [i];
for (n=0; n<i; n++)
{
cout << "Enter marks " << n + 1 << ": ";
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
{
cout << p[n] << " ,";
sum += p[n];
avg = sum/p[i];
}
cout << "\nSum of marks is: " << sum << endl;
cout << "Average marks is: " << avg << endl;
delete[] p;
return 0;
}
sum and average are not initialized they are not default initialized to 0. So on lines 26 and 27 they are probably going to have an arbitrary number. By the way your average calculation is pretty wrong. Average = Sum / Count. So in other words if you have 1 4 9 then it would be Average = 14 / 3 = 4.67
*forgot to mention this but you should put the average outside the loop. There is no reason to calculate it each time. You could also add to the sum while you input the numbers.
Sum is uninitialized, set it to 0 somewhere before you use it; it is accumulating garbage + p[n].
And use: avg = sum/i; not p[i].
p[i] is beyond the array by 1, and has no useful data that you would need.
Average could also be calculated after the accumulation of sums; can save 1 procedure per cycle during second for loop; maybe.