0

I wrote a program that solves graphing programs. I am still very new to c++ and mt program is very very rough around the edges but my main problem is when the function returns the value to the main function it outputs random numbers in stead of the correct value. And to make sure that the functions were doing the math correctly I had it output the value before sending it to the main function. here is the code. And again forgive me for its roughness.

```
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
// this function is for finding the value of b
float graph (float m, float x2, float y2)
{
float b;
m = m * x2;
cout << m;
system("pause");
if (m < 0)
{
m = m * -1;
b = m + y2;
}
else b = m + y2;
cout << m;
system("pause");
cout << b;
system("pause");
return (b);
}
// this function is for finding the value of m
float slope (float y2, float y1, float x2, float x1)
{
float m;
// in order to find the slope you must do the formula below
m = (y2 - y1)/(x2 - x1);
cout << m;
system("pause");
// here i send the values of m, x2 and y2 to find the value of b
graph (m, x2, y2);
return(m);
}
int main()
{
float x2, x1, y2, y1;
int m;
// i put keep as a cin veraible so that it keeps on running so that i can see my result. dont know how to keep it from automatically shutting down
cout << "Input y2, y1, x2, x1 in that order and press enter after each input \n";
//inputs all the values. or coordanints as in "find the slope of (x,y)(x,y) then put it into a x=mx+b form"
cin >> y2;
cout << "\n";
cin >> y1;
cout << "\n";
cin >> x2;
cout << "\n";
cin >> x1;
cout << "\n";
// here i'm sending the values to the slope function
slope (y2, y1, x2, x1);
//here i display the formula using the results of slope and graph
cout << "y=" << slope << "x" << graph << "\n";
// I added this later to see the values of graph and slope because they werent making sense
cout << graph << "\n";
cout << slope;
system("pause");
return 0;
}
```