Solvedhelp with program please

Posts 1–15 of 15 · Page 1 of 1
help with program please
thanks for anyone who helps but i cannot seem to figure out why the second function does not output the code that i tell it too?

Code:
#include<iostream>
using namespace std;

int main(){

      int slopeVal=0;
      int slopeVal2=0;

      cout<<"Please input the first slope value: ";
      cin>>slopeVal>>endl;
      cout<<"Please input the second slope value: ";
      com>>slopeVal2>>endl;

return 0;
}

int findLine(int slopeVal, int slopeVal2){

   if(slopeVal==slopeVal2){
            cout<<"The two lines are parallel.";}
   else if(slopeVal==(slopeVal2*-1)){
            cout<<"The two lines are perpendicular.";}
   else{
            cout<<"The lines are normal intersected";}
}
I'm guessing you get the error "error C3861: 'findLine': identifier not found"?
Code:
#include<iostream>
using namespace std;

/* The reason you get the "identifier not found" error is because findLine is after main.
*  The compiler never lets the program know there is a function called findLine that takes
*  two int parameters and returns an int value.
*  To fix the error put the function + scope before main or just the function and parameters like this:
int findLine(int slopeVal, int slopeVal2);*/

int main(){

	int slopeVal = 0;
	int slopeVal2 = 0;

	cout << "Please input the first slope value: ";
	cin >> slopeVal >> endl;	//	cin does not use endl; endl clears the buffer on the output stream. cin is the input stream.
	/* correct way:
	cin >> slopeVal; */
	cout << "Please input the second slope value: ";
	com >> slopeVal2 >> endl;	//	I think you meant "cin" not "com". Also, refer to the one above.
	/* correct way:
	cin >> slopeVal2;*/

	/* You never actually call findLine.
	findline(slopeVal, slopeVal2);*/

	return 0;
}

int findLine(int slopeVal, int slopeVal2){
	/* Nothing is really in error here except you need to return a value. since findLine is type int it's expecting you
	*  to return an int value. 
	*  You never return an int value. */
	if (slopeVal == slopeVal2){
		cout << "The two lines are parallel.";	//	Works, but it does not endl (which clears the buffer).
	}
	else if (slopeVal == (slopeVal2*-1)){
		cout << "The two lines are perpendicular.";	//	Same as the first.
	}
	else{
		cout << "The lines are normal intersected";	//	Same as the first and second.
	}
	/* no return at the end of the function, all you do is cout.
	*  correct way:
	return 0;*/
}
@disturbed14x
After reading both of your codes you've posted here recently, I figured.
You don't know what you are doing. No offence.

But I would recommend to go read a book to read up the basics.
Quote Originally Posted by ERGaergaergaergaergearg View Post
@disturbed14x
After reading both of your codes you've posted here recently, I figured.
You don't know what you are doing. No offence.

But I would recommend to go read a book to read up the basics.
I got the impression he was reading a book based on his first post. And then this one, a step backwards from the other, might just have been him trying to mess around with calling functions.

I agree, though. If you're not already reading a book, pick one up and read it...

My recommendation, and the recommendation of thousands of others, would be C++ Primer 5th Edition (*Not* C++ Primer Plus). Though this book is 1000 pages, I've been reading it for a few months now and I'm only now getting into Chapter 10. It's extremely in depth and goes over the basics very, very, well. (Just to give you an idea about the book I read each chapter, writing everything I read. At the end I go back through everything I wrote and copy/paste everything important into one file. Here's a link to the notes, up to Chapter 6.)

Also, you might want to check out The Definitive C++ Book Guide and List, if you don't want to go with a 1k page book.
i reconfigured the code i was wondering if anyone would be able to tell me why it continues to output is always "The lines are parallel"? thank you all for your time in trying to help me.

i do have a book and i am trying to learn.
Quote Originally Posted by disturbed14x View Post
i reconfigured the code i was wondering if anyone would be able to tell me why it continues to output is always "The lines are parallel"? thank you all for your time in trying to help me.

i do have a book and i am trying to learn.
Post the code, not a screenshot.
Quote Originally Posted by disturbed14x View Post
i reconfigured the code i was wondering if anyone would be able to tell me why it continues to output is always "The lines are parallel"? thank you all for your time in trying to help me.

i do have a book and i am trying to learn.
I don't know why you're trying to over complicate this and make extra lines of code...

Code:
//	judge if two lines are parallel, perpendiculr, or neither
#include <iostream>
using namespace std;

int findLine(int, int);

int main()
{
	int num, slopeVal, slopeVal2;
	
	cout << "Please input two slope values: " << endl;
	cin >> slopeVal >> slopeVal2;
	num = findLine(slopeVal, slopeVal2);

	switch (num){
	case (0) :
		cout << "The lines are parallel." << endl;
		break;
	case (2) :
		cout << "The lines are perpendicular." << endl;
		break;
	case (3) :
		cout << "The lines are neither." << endl;
		break;
	default:
		cout << "Invalid lines." << endl;
	}
}

int findLine(int x, int y)
{
	if (x == y)
		return 0;
	else if (x == (y * -1))
		return 1;
	else
		return 2;
}
This can be even more efficient and smaller but this will do what you want. You really need to go back to the basics and study them some more.
It's because you're checking the values when they're still 0
Even smaller, inline.
Code:
//	judge if two lines are parallel, perpendiculr, or neither
#include <iostream>
using namespace std;

int main()
{
	int slopeVal, slopeVal2;
	
	cout << "Please input two slope values: " << endl;
	cin >> slopeVal >> slopeVal2;
	cout << ((slopeVal == slopeVal2) ? "The lines are parallel." : (slopeVal == (slopeVal2 * -1)) ? "The linesa re perpendicular." :
		(slopeVal != slopeVal2) ? "The lines are neither." : "Invalid lines.") << endl;
}
Quote Originally Posted by Biesi View Post
It's because you're checking the values when they're still 0
Thank you very much that comment helped me out a lot. all i had to do was move a portion of the code.
Quote Originally Posted by InunoTaishou View Post
Even smaller, inline.
And unreadable
Quote Originally Posted by Biesi View Post


And unreadable
It's eligible if you understand the ternary operator.

Code:
//	judge if two lines are parallel, perpendiculr, or neither
#include <iostream>
using namespace std;

int main()
{
	int slopeVal, slopeVal2;
	
	cout << "Please input two slope values: " << endl;
	cin >> slopeVal >> slopeVal2;
	cout << ((slopeVal == slopeVal2) ? "The lines are parallel." : 
			(slopeVal == (slopeVal2 * -1)) ? "The linesa re perpendicular." :
			(slopeVal != slopeVal2) ? "The lines are neither." : 
			"Invalid lines.") << endl;
}
Just a thought:

if(slopeVal == (slopeVal2 * -1))... for perpendicular lines is wrong

Perpendicular lines are opposite reciprocals.
For example, 2x and -1/2x, not 2x and -2x
Quote Originally Posted by disturbed14x View Post
thanks for anyone who helps but i cannot seem to figure out why the second function does not output the code that i tell it too?

Code:
#include<iostream>
using namespace std;

int main(){

      int slopeVal=0;
      int slopeVal2=0;

      cout<<"Please input the first slope value: ";
      cin>>slopeVal>>endl;
      cout<<"Please input the second slope value: ";
      com>>slopeVal2>>endl;

return 0;
}

int findLine(int slopeVal, int slopeVal2){

   if(slopeVal==slopeVal2){
            cout<<"The two lines are parallel.";}
   else if(slopeVal==(slopeVal2*-1)){
            cout<<"The two lines are perpendicular.";}
   else{
            cout<<"The lines are normal intersected";}
}
You never actually call the 'findLine' function in the code you first posted...


If you're now seeing output from the findLine function you did more than just rearrange the code...please post the current version of the code..nobody here is a mind reader.
(Tip: a function must be declared before (ie. above, in the source file) it is called...that's why rearranging might have made a difference...see "function prototype" in your book. But again, you don't actually call the findline function in the code you posted so the function shouldn't ever be getting expected.)
I guess it's solved by now.
Closed.
Posts 1–15 of 15 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?