array won't define

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
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
double a[9];
double voltage,temperature;


int main()
{
	cout << "What is the Voltage in mV: ";
	cin >> voltage;
	if (voltage >= -6.18 && voltage <= -4.648)
		double a[]= {-1.9243000e+02, -5.4798963e+00, 5.9572141e+01, 1.9675733e+00, -7.8176011e+01, -1.0963280e+01, 2.7498092e-01, -1.3768944e+00, -4.5209805e-01};
	else if (voltage >= -4.648 && voltage <= 0)
		double a[]= {-2.9243000e+02, -7.4798963e+00, 1.9572141e+01, 9.9675733e+00, -6.8176011e+01, -8.0963280e+01, 4.7498092e-01, -1.3768944e+00, -4.5209805e-01};
	else if (voltage >= 0 &&  9.288 <= 0)
		double a[]= {-2.9243000e+02, -7.4798963e+00, 1.9572141e+01, 9.9675733e+00, -6.8176011e+01, -8.0963280e+01, 4.7498092e-01, -1.3768944e+00, -4.5209805e-01};
	else if (voltage >=  9.288 && voltage <= 20.872)
		double a[]= {-2.9243000e+02, -7.4798963e+00, 1.9572141e+01, 9.9675733e+00, -6.8176011e+01, -8.0963280e+01, 4.7498092e-01, -1.3768944e+00, -4.5209805e-01};
	else
		return 0;
	double vmt=voltage-a[1];
	temperature=a[0]+((vmt)*(a[2]+(vmt)*(a[3]+(vmt)*(a[4]+a[5]*(vmt)))))/(1+(vmt)*(a[6]+(vmt)*(a[7]+(a[8]*(vmt)))));
	cout << endl << temperature;
	system ("PAUSE");
	return 0;
}



This is my program. When ever i try to input anything it always gives me an answer of 0. The array doesn't seem to be defining and i have no idea why. 3 of the arrays are identical because i am in no mood to input the real values before I get this to work.
Those arrays inside of your if statements are creating a new array called a and hiding the old one, not modifying the one you have in global space.
Topic archived. No new replies allowed.