This is code for the slope intercept formula y = mx + b

I am supposed to find the slope (y2 - y1) / (x2 - x1) and have the user input the b for the y = mx + b in my program. Once the user does that I do the same exact thing again so I can compare if the lines intersect or not.

the only problem with my code is that I am getting an unresolved external. Can anyone help me out??

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int Line1();
int Line2();
void solution_identifier();
void Results();

int Line1()
{
	float x, y, x2, y2;
	float Y_intercept;

	cout << "Please enter your coordinate points begining with x: ";
	cin >> x;
	cout << "Now enter your Y coordinate point: ";
	cin >> y;
	cout << "Now your X2 coordinate point: ";
	cin >> x2;
	cout << "Finally your Y2 coordinate point: ";
	cin >> y2;
	float slope((y2 - y) / (x2 - x));
	cout << slope << "X is your slope." << endl;

	cout << "Please enter the Y intercept, which would be the b in the slope-intercept formula, from your 1st formula: ";
	cin >> Y_intercept;

	return 0;
}


int Line2()
{
	float a, c, a2, c2;
	float Y_intercept2;

	cout << "Please enter your coordinate points begining with a: ";
	cin >> a;
	cout << "Now enter your c coordinate point: ";
	cin >> c;
	cout << "Now your a2 coordinate point: ";
	cin >> a2;
	cout << "Finally your c2 coordinate point: ";
	cin >> c2;
	float slope2((c2 - c) / (a2 - a));
	cout << slope2 << "X is your slope." << endl;

	cout << "Please enter the Y intercept from your 2nd formula: ";
	cin >> Y_intercept2;

	return 0;
}

void solution_identifier(float slope, float slope2, float Y_intercept, float Y_intercept2)
{
	if (slope == slope2 && Y_intercept == Y_intercept2)
	{
		cout << "The two lines intersect forever meaning there are an infinite number of solutions." << endl;
	}
	else 
		if (slope == slope2 && Y_intercept != Y_intercept2)
		{
		cout << "The two lines are paralell which means there are no solutions." << endl;
		}
		else if (slope != slope2)
			{
				cout << "The two lines intersect which means there is only one solution." << endl;
			}
}

void Results(float slope, float slope2, float Y_intercept, float Y_intercept2)
{
	cout << "The slope of line 1 is: " << slope << endl;
	cout << "and it's Y intercept is: " << Y_intercept << endl;
	cout << "The slope of line 2 is: " << slope2 << endl;
	cout << "and it's Y intercept is: " << Y_intercept2 << endl;
}

int main(float x, float y, float x2, float y2, float a, float c, float a2, float c2, float Y_intercept, float Y_intercept2)
{
	cout << "Quick Note: Any user interacting with this part of the program should be aware" << endl;
	cout << "it is assumed that your formula is in the slope-intercept form(Y = mX + b)." << endl;
	Line1();
	Line2();
	Results();
	solution_identifier();
	system("PAUSE");
	return 0;
}
Member Avatar for MonsieurPointer

Where do the errors occur? Which line numbers exactly?

My first guess is this:

int Line1();
int Line2();
void solution_identifier();
void Results();
void solution_identifier(float slope, float slope2, float Y_intercept, float Y_intercept2)

and my second guess is this:

int main(float x, float y, float x2, float y2, float a, float c, float a2, float c2, float Y_intercept, float Y_intercept2)

You have the wrong signatures (parameters) for main, and your function's signatures do not match those of your prototypes.

In addition your program will never work, because most of your variables are created within the scope of your functions (e.g. slope, slope2) and are never passed to the Results function. All in all, your code is quite the mess...

can you show me?

commented: *sigh* Yet another attempt at an easy grade. -3

No. You know the site rules. We're not here to do your work for you, we're here to guide you to your own success.

You've been doing this long enough, you should know what the proper signature(s) for the main function is/are by now. Re-work your main() into the proper form yourself. Then go from there.

Pay close attention to your scoping rules; by now, you should have some concept of what those are and how they work as well.

I thought the site is supposed to be a forum to help people when they need it. Also, if they have the work and they tried, how come we can't help them??

I thought the site is supposed to be a forum to help people when they need it. Also, if they have the work and they tried, how come we can't help them??

It is. But, as evidenced by you habitually asking for code to copy, your "need" is not any sort of reasonable assistance, it's an easy grade. This "need" is one that members in good standing make a conscious effort to not satisfy in order to not only help you learn what you are supposed to, but to protect the reputation of the site as a whole.

With you, it's the same pattern every time:

  1. Belch out junk code so it looks like you tried (about half the time you don't even do that)
  2. Get a response
  3. Attempt to buffalo people into giving you fully functional code

THIS IS CHEATING and you need to stop it.

What you need to remember is that many (if not most) of the members here are professionals. At some point they will no longer be in the workforce. When they leave the industry, they will need to be replaced. Would you want your replacement to be a worthless meat-sack that can't program their way out of a paper bag or someone that actually knows what they're doing? If you continue to cheat your way through your classes, you'll wind up as one of the worthless meat-sacks, not someone who knows what they're doing; and I pitty the company that winds up hiring you.

This code is for my friend. I have done this program already, I just wanted to try and find a little more of an advanced way of doing it. I mean, I still have 3 years left of school for programming, so I just needed some help because I want to code like this and I wanted to see if it was possible is all.

I have code and sometimes i had to figure out different ways to code. I haven't put up any code lately unless i was really stumped, you know? I have only taken programming 1 which teaches Beginning C++ Through Game Programming Second Edition by Michael Dawson and DirectX11, which I am doing now. I have a couple files from my classes on what I have done. I don't like to fail in my classes, and I want to continue to do good in them. I am now programming slope intercept formulas, but in another post, i have x,y,z, slope formula help, I have written code and i wanted to find a way to input x,y,z, without saying

cout << "What is the X coordinate of line1;
cin >> x1;
cout << endl;

cout << "What is the Y coordinate of line1;
cin >> y1;
cout << endl;

cout << "What is the X coordinate of line2;
cin >> x2;
cout << endl;

cout << "What is the Y coordinate of line2;
cin >> y2;
cout << endl;

float slope1 = ((y2- y1) / (x2 - x1));
cout << " y = mx + b is your formula" << endl;
cout << endl;

cout << "M is your slope. Your slope is: " << slope1 << " x + b" << endl;
cout << endl;
cout << "What would you like b to be? ";
cin >> b;

and instead of those I actually used arrays: float line1[3], line2[3];
but I used the same input method and my teacher did not know programming. She is a college algebra major. That is why I use this forum for assistance. I'm sorry for using this site to my advantage. I'm sorry.

this code is my friend's and he really isnt a good programmer. I try and help him, but he tried using functions, which i sometimes do. I wanted to know if it is possible to do it this way. I am also sorry for lying to you and the FORUM.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.