I'm trying to write a program using a dynamic array that will sum all the numbers before the number entered. (You enter 3 it does 1+2+3=6) Keep getting really wrong output numbers but can't find the error.
Code:#include <iostream> using namespace std; void summation(int sumArray[], int array_size); typedef int* IntArrayPtr; int n, array_size, sum = 0; int main() { char choice = 'c'; while (choice == 'c' || choice == 'C') { cout <<"What is your ending number?: "; cin >> array_size; IntArrayPtr sumArray =; sumArray = new int[n]; summation(sumArray, n); cout <<"To quit enter q; to continue enter c."; cin >> choice; } if (choice == 'q' || choice == 'Q') { return 0; } } void summation(int sumArray[], int n) { while (n<array_size) {sum=sum + sumArray[n]; cout <<sum; n++;} cout <<"The sum of 1 to "<<array_size <<" is "<<sum<<endl; }



LinkBack URL
About LinkBacks



