Need help graphing a function

Hey guys, fairly new to programming, working on creating a calculator. I have all the functions in place and everything seems to work perfectly. I have a function double evaluate(string input); that will calculate anything as complex as parentheses and exponents, following order of operations.

I also have a rectangle class that I wrote a while back. It uses bgi graphics to draw simple rectangles, and I've been using it for most of my graphics.

I'm typing it all up in visual studio, but compiling it with the CS 1300 GNU compiler I got in my C++ class so that I can use the graphics functions it comes with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for(int i = 0; i < 900; i = i + 2) //It's a 900x900 window, so I draw a new 
				   //rectangle every two pixels.
{
	x = static_cast<double>(i-450)/scale; //Sets x values
	temp = function; //This lets me evaluate temp while keeping function the 
			 //way it is
	num = numToStr(x);
	for(int j = 0; j < temp.length(); j++) //The issues happen here, in this 
		      //loop. When it's commented out the program runs smoothly.
	{
		if(temp[j] == 'x')
			temp.replace(j, 1, num); //Replaces x with the current 
						 //value in the function.
	}
	x = evaluate(temp); //Evaluates the function
	rect.setPt(i,450-static_cast<int>(x)); //Creates  a rectangle (2x2) at 
					       //point (x,y)
	rect.draw();
}


Everything works perfectly, and runs the way it should. All my functions, including the code where I input the value for x, work perfectly in my calculator. But not when I graph it. It doesn't give me an error message, it just says the program has stopped working and gives me an option to debug. I'm not familiar enough with visual studio debugging to use that option. I tried it, and it just confused me. Not sure if it would help anyhow.

So there's my issue. I have no idea what's going on, can I get any help on this, please? Thank you!

--chokfull
Last edited on
Topic archived. No new replies allowed.