Writing a very basic graphing program

I can't quite seem to figure out exactly why this won't work...

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;

int getx(int y, int m, int b) {
	int x;

	y=y-b;
	x=y/m;

	return(x);
}

void drawgraph(int slope,int yi,int xscale,int yscale) {
	for(int cy=(yscale*8);cy==0;cy--) {
		for(int cx=(xscale*8);cx==0;cx--) {
			if (cy!=(yscale*4)) {
				if (cx!=(xscale*4)) {
					if (cx==(getx(cy,slope,yi))) {cout<<"*";}
					else {cout<<" ";}
				}
				else {cout<<"*";}
			}
			else {cout<<"*";}
		}
	cout<<"\n";
	}
}

int main() {
	int m;
	int b;

	int xscale;
	int yscale;

	cout<<"y = mx + b";
	
	cout<<"\n\nSlope = ";
	cin>>m;
	cin.ignore();

	cout<<"\ny-intersect = ";
	cin>>b;
	cin.ignore();

	cout<<"\n\nx-scale = ";
	cin>>xscale;
	cin.ignore();

	cout<<"\ny-scale = ";
	cin>>yscale;
	cin.ignore();

	system("cls");

	drawgraph(m,b,xscale,yscale);
	cin.get();

	return 0;
}


The program is designed to graph linear lines using asterisks. It puts 4 spaces in between whole points (to explain the xscale*8 thing).

It's based on the y=mx+b thing.

Pretty much, it should start in the top left and work it's way across, determining if the line intersects at the given position.

It starts at the highest possible Y value and works across the X axis. then going down by 0.25 of a point on the Y axis... I think...

Anyways, hopefully it's some stupid little mistake and I don't have to rewrite the whole thing :P

Thanks
Line 14 should read:
for(int cy=(yscale*8);cy!=0;cy--) {

and line 15 should read:
for(int cx=(xscale*8);cx!=0;cx--) {

otherwise the for loops won't run

at least that will be a start - you'll get something on the screen then.
Last edited on
Topic archived. No new replies allowed.