How do I create a graph and plot coordinates in C++?

Uconn411

Member
Jul 15, 2000
152
0
0
I wrote the following code based on y=ax+b. It will ask a user to input 2 values (a and b), and show them the values of (x,y). Also, the user is asked to input a char marker, in which the line of the graph will be drawn. Problem is, I don't know how to draw a graph (with x and y axis), and then to plot the values. Here is what I have so far:

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>



int main()
{


{
double slope, intercept, y;
char graph_char;

cout << "Enter a and b from the equation y = ax + b:\n";
cout << "a: ";
cin >> slope;
cout << "b: ";
cin >> intercept;

cout << "\nY: ";

for (int x=0;x<21;x++)

{
y = (slope * x) + intercept;
cout << "(" << x << "," << y << ") ";
}

cout<< "\nEnter the character marker for the graph: ";
cin>> graph_char;

}

return 0;
}


Thanks for any advice....
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
You need some sort of graphics library.
Hit google and look up Dislin. It's the simplist thing I've found for basic plotting.