Hi, there are several threads on this issue, but none seem to give me a good answer. My current code is this (This program plots points on a graph) :
//Put line equasion into arrays.
#include <iostream>
using namespace std;
double getData(int counter, double m, double b) {
int yValue = counter * m;
yValue = yValue + b;
return yValue;
}
int main() {
cout << "Putting Y = MX+B into arrays xData[] and yData[]" << endl;
int xMin = -10;
int xMax = 10;
double b = 0;
double m = 2;
//int yMin = xMin*m+b;
//int yMax = xMax*m+b;
int counter = xMin;
double xData[xMax - xMin];
double yData[xMax - xMin];
double yTemp;
for (counter; counter <=xMax; counter++) {
yTemp = getData(counter, m, b);
xData[counter] = counter;
yData[counter] = yTemp;
cout << "(" << xData[counter] << "," << yData[counter] << ") " << endl;
}
cout << yData[-5];
system("pause");
return 0;
}
The code returns the following output:
Putting Y = MX+B into arrays xData[] and yData[]
(-10,2.24756e-307)
(-9,-18)
(-8,-16)
(-7,3.47668e-310)
(-6,0)
(-5,1.78923e-307)
(-4,2.22516e-307)
(-3,-6)
(-2,-4)
(-1,-2)
(0,0)
(1,2)
(2,4)
(3,6)
(4,8)
(5,10)
(6,12)
(7,14)
(8,16)
(9,18)
(10,20)
1.78932e-307Press any key to continue . . .
What is the deal? I did this source code on paper (Like what the values would hold step by step) and even had the program skip yData[] entirly and give a correct answer. It seems having the data in the array is screwing it up. If anyone can help, that would be great!
--Dylan
PS, no matter what M is, the weird outputs stay the same.