array's to the power

Hey all,

so I am trying to make a code with one constant array and another in which I input the numbers then find a third array by doing the 1st*(second^2). When I add them or multiply them it works perfectly but for some reason i get an error on the 5th time it loops when i do the proper formula. Any chance any of you know what I could be doing wrong? here's my code

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


int main() {

int resistance []={16,27,39,56,81};
int x=5;
double current[5];
int i;
double sumcurrent=0;
double power[i];

cout<<"enter the numbers you want for current: "<<endl;


for (i=0; i<x; i++)
{
cin>>current[i];
sumcurrent=current[i]+sumcurrent; //total of current
}

for (i=0; i<x; i++)
{
power[i] =resistance[i]*pow(current[i],2);
cout<<power[i]<<endl; //doesn't work on last array element
}
return 0;
}
double power[i]; Dangerous, unpredictable, nonstandard.
You probably meant to write double power[5]; ?
yes you were absolutely right. but when I put power[5] does that change power [i] later on in the code? I am unsure of what the change does in reference to the code but it removed the error so obviously you were right.
Topic archived. No new replies allowed.