-
Help Access Violation
Here is my code
Code:
#include <iostream>
using namespace std;
int main ()
{
double alpha [50];
int x;
for(x = 1; x <= 50; x++);
{
if (x <=25)
alpha[x] = x * x;
else
alpha[x] = 3 * x;
cout << alpha[x];
if ( x == 9)
cout << endl;
}
return 0;
}
and this is what keeps popping up when i debug it and don't know what it means
Unhandled exception at 0x40632000 in alpha.exe: 0xC0000005: Access violation.
-
Arrays start at index 0, not 1. Change your loop so that it loos through the values 0..49 inclusive, instead of 1..50 inclusive
-
tried that and here is the code with the new array values but still get the same error as before
Code:
#include <iostream>
using namespace std;
int main ()
{
double alpha [49];
int x;
for(x = 0; x <= 49; x++);
{
if (x <= 24)
alpha[x] = x * x;
else
alpha[x] = 3 * x;
cout << alpha[x];
if ( x %10 == 9)
cout << endl;
}
return 0;
}
-
Because now you've reduced the size of the array to 49, so it's still overflowing... Keep the size of the array at 50
-
Well i did that and now I get
"Stack around the variable 'alpha' was corrupted."
-
Code:
#include <iostream>
using namespace std;
int main ()
{
double alpha [50]; // 50 doubles: indexed 0 to 49
int x;
for(x = 0; x <= 49; x++) // ; semicolon? :)
{
if (x <= 24)
alpha[x] = x * x;
else
alpha[x] = 3 * x;
cout << alpha[x];
if ( x %10 == 9)
cout << endl;
}
return 0;
}
-
Oh my thank you for that lol :)