Closing Console Without Error
Dec 29, 2011 at 3:31pm UTC
hi i'm very very beginner so i have to write a program with arrays.program works just fine but when it's time to close console it says that "Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted." so here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
int i, a[10], positive=0, product=1, sum=0, negative=0, ipositive=1, inegative=1, all;
char k,y,n,prog;
for (i=1; i<=10; i++){
cout << "A[" <<i<<"]= " ;
cin >> a[i];
sum+=a[i];
product*=a[i];
if (a[i]>0){
ipositive*=a[i];
positive++;
}
else if (a[i]<0){
negative++;
inegative*=a[i];}}
cout << "\nPositive Detected:\a " << positive << endl;
cout << "\nNegative Detected:\a " << negative << endl;
cout << "\nPositive Product:\a " << ipositive << endl;
cout << "\nNegative Product:\a " << inegative << endl;
cout << "\nSum:\a " << sum << endl;
cout << "\nProduct:\a " << product << endl;
cout << "\nDo You Want To Add All Results? Y/N: " ;
cin >> k;
prog: all=positive+product+sum+negative+ipositive+inegative;
if (k=='y' )cout << "\nAddition Of All:\a " << all;
else if (k=='n' ){ cout << "\nIt's Your Choice, Goodbye" ;
getch();
return 0;}
else {system("pause" );
return 0;}
cout << "\n\nPress Any Key To Exit..." ;
getch();
return 0;
}
Last edited on Dec 29, 2011 at 3:34pm UTC
Dec 29, 2011 at 3:54pm UTC
Array index goes from 0 to n-1
Dec 29, 2011 at 5:05pm UTC
hey thanks mate i got it thank you ;)
Topic archived. No new replies allowed.