1. get values from user and enter them into the array
2. call a function that accumulates a running total of all the elements in the array
Upon running the program, I get this error in Visual Studio:
Run-Time Check Failure #2 - Stack around the variable 'pounds' was corrupted.
The thread 'Main Thread' (0x17f0) has exited with code -1073741510 (0xc000013a).
The program '[7292] Monkey Business.exe: Native' has exited with code -1073741510 (0xc000013a).
The program runs and debugs ok, until it reaches line 26 where I get a breakpoint error, and a prompt where it asks me to Break or Continue. I don't understand what the problem is. Any help is appreciated. Can anyone explain what might be wrong?
#include <iostream>
using namespace std;
const int NAMES = 3;
const int DAYS = 7;
void getTotal(int array[][DAYS]);
int main()
{
int pounds[NAMES][DAYS] = { };
for (int a = 0; a < DAYS; a++)
{
for (int i = 0; i < NAMES; i++)
{
cout << "Please enter the number of pounds consumed by Monkey " << i+1 << " on day " << a+1 << ": ";
cin >> pounds[a][i];
}
cout << endl;
}
getTotal(pounds);
system("pause");
}
void getTotal(int array[][DAYS])
{
int total = 0;
for (int a = 0; a < DAYS; a++)
{
for (int i = 0; i < NAMES; i++)
{
total+= array[a][i];
}
}
cout << total << endl;
}

New Topic/Question
Reply




MultiQuote



|