Unwanted variable change in array

#include <iostream>
#include <cmath>
using namespace std;



int main() {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
double e = 0;
double j = 0;

double radius[b];
double area[a];
double circum[c];
double new_radius[d];

string input;
string as = "A";
string AS = "a";
string de = "D";
string DE = "d";

// radius
while ( b < 5) {
cout << "Radius of circle " << b + 1 << ": ";
cin >> radius[b];
b = b + 1;
}
// the problem is past this point
b = 0;
// area
while (b < 5) {

area[a] = pow(radius[b],2) * 3.14159;
b = b + 1;
a = a + 1;
cout << radius[0] << endl;
}
b = 0;
// circum
while (c < 5) {
circum[c] = radius[b] * 2 * 3.14159;
c = c + 1;
b = b + 1;
}

a = 0;
b = 0;
c = 0;


cout << "Circle" << " " << "Area" << " " << "Circumfance" << " " << "Radius" << endl;

while (d < 5) {
cout << "Circle " << d + 1 << " " << area[a] << " " << circum[c] << " " << radius[b] << endl;
d = d + 1;
a = a + 1;
b = b + 1;
c = c + 1;


Here's some of it. The problem is radius[0], radius[1], and radius[2] keep giving out the wrong numbers they end up with area[2], area[3], and area[4]
Please use code tags around your code.

Also, your array declarations are incorrect. You can't declare static arrays of variable size like you are doing in standard C++. Also, at one point you are printing radius[0] every iteration instead of radius[b] as I think you meant to.

Stylistically, you have a large number of while loops that would be better served as for loops, among other things.
-radius[0] was on purpose because i wanted to see where the program went wrong.

-I don't know what you mean by this: "You can't declare static arrays of variable size like you are doing in standard C++"

-sorry for the while loops, still pretty new to the whole programming and I feel most comfortable with while loops
The major problem is you're declaring your arrays with size zero:

1
2
3
4
5
6
7
8
9
10
int a = 0;
int b = 0;
int c = 0;
int d = 0;

//b, a, c, and d are zero here!
double radius[b];
double area[a];
double circum[c];
double new_radius[d];


It looks like you wanted all your arrays to have size 5. In which case, you would want to declare them like this:

1
2
3
4
double radius[5];
double area[5];
double circum[5];
double new_radius[5];


And since 5 is used in multiple places, you might want to make it a constant.
Wow I'm such an idiot why didn't I notice that! I'm such a noob...lol. Thanks guys it works.
Topic archived. No new replies allowed.