| | |
C++ Simple Math Problems
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 19
Reputation:
Solved Threads: 0
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) :
The code returns the following output:
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.
C++ Syntax (Toggle Plain Text)
//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; }
C++ Syntax (Toggle Plain Text)
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 . . .
--Dylan
PS, no matter what M is, the weird outputs stay the same.
0
#2 31 Days Ago
C++ Syntax (Toggle Plain Text)
int xMin = -10; int xMax = 10; double xData[xMax - xMin];
C++ Syntax (Toggle Plain Text)
int counter = xMin; for (counter; counter <=xMax; counter++) {
counter runs from -10 to 10 Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
•
•
Join Date: Oct 2009
Posts: 19
Reputation:
Solved Threads: 0
0
#3 31 Days Ago
•
•
•
•
xData contains 20 elements starting from 0 to 19.C++ Syntax (Toggle Plain Text)
int xMin = -10; int xMax = 10; double xData[xMax - xMin];
WhileC++ Syntax (Toggle Plain Text)
int counter = xMin; for (counter; counter <=xMax; counter++) {counterruns from -10 to 10
0
#5 31 Days Ago
•
•
•
•
Thanks people, I got the answer from another fourm I was posting on. The problem was no using negative values in the array identifier ers. So i had to make a new var..
xData[xMax - xMin] equals to xData[20] because xMax - xMin = 20 . So allowed index should be in range of 0 to 19. Your counter runs from -10 to 10 and you use counter as index of your array which is not in range for the first 10 negative numbers. Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
![]() |
Similar Threads
- A Simple Math Riddle (Java)
- custom made queue/stack - having problems (C++)
- Help with Simple Math Problem (Python)
- long math problems (C++)
- Simple Math + Javascript (JavaScript / DHTML / AJAX)
- I want to build auto math solver in my site (Computer Science)
- Weird, weird problems with fstream (C++)
- Discrete Math or Data structure (Computer Science)
- Virgin programmer (Java)
Other Threads in the C++ Forum
- Previous Thread: How do I set shared ptr to NULL
- Next Thread: Need help....
| Thread Tools | Search this Thread |
api append array arrays background binary bitmap c# c++ calculator cast char char* class cms compile console convert data database delayload delete desktop development dialog download dynamic ebook ect embed encryption error examples faq file frequency fstream function functions game global graph guessing href image index input int java jsp kioti16 line list listbox math memory multi multiple mysql newbie number numbers opengl output performance perl php pointer primenumbersinrange print problem program programming python random read recursion recursive return search set sql stop string strings superclass template text tree university url variable vb visual visualbasic.net visualstudio web win32 wxwidgets xslt






