### Multiple values for function

Hello guys I have a function that calculates a destination points for x and y.. and when I have the actual values I want to send them back to my main program to have them displayed as results.. but I am running into issues just because I am unsure how to do it.. My professor said to pass them through reference parameters but I am unsure how to

any help would be appreciated! Thanks in advance!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289`` ``````#include #include using namespace std; void displayMenu(void); double engineerOne(double pointxI, double pointxII, double pointyI, double pointyII); double engineerTwo(double pointxI, double pointxII, double pointyI, double pointyII); double engineerThree(double verticalAngleD, double velocityMile); void engineerFour(double pointxI, double pointyI, double pointDistance, double angleDegree, double destinationX, double destinationY); void getPoints(double& pointx, double& pointy); void custServiceOne(double& pointxI, double& pointxII, double& pointyI, double& pointyII); void custServiceTwo(double& pointxI, double& pointyI); void custServiceThree(double& verticalAngleD, double& velocityMile); void custServiceFour(double& pointxI, double& pointyI, double& pointDistance, double& angleDegree); int main() { char again; int programChoice; double pointxI, pointxII, pointyI, pointyII, verticalAngleD, velocityMile, pointDistance, angleDegree, TwopointDistance, degreeAngle, distanceFeet, destinationX, destinationY; cout << endl << "Compute Different Awesome Equations" << endl << endl; do { do { displayMenu(); cout << "Please enter your selection: "; cin >> programChoice; if (programChoice > 5 || programChoice <= 0) { cout << endl << "Please enter a number from 1 to 5"; cout << endl << endl; } } while (programChoice > 5 || programChoice <= 0); if (programChoice == 1) { custServiceOne(pointxI, pointxII, pointyI, pointyII); } else if (programChoice == 2) { custServiceTwo(pointxI, pointyI); } else if (programChoice == 3) { custServiceThree(verticalAngleD, velocityMile); } else if (programChoice == 4) { custServiceFour(pointxI, pointyI, pointDistance, angleDegree); } if (programChoice == 1) { TwopointDistance = engineerOne(pointxI, pointxII, pointyI, pointyII); } else if (programChoice == 2) { degreeAngle = engineerTwo(pointxI, pointxII, pointyI, pointyII); } else if (programChoice == 3) { distanceFeet = engineerThree(verticalAngleD, velocityMile); } else if (programChoice == 4) { engineerFour(pointxI, pointyI, pointDistance, angleDegree, destinationX, destinationY); engineerFour(pointxI, pointyI, pointDistance, angleDegree, destinationX, destinationY); //I need to have engineer four calculate these two destinations here } if (programChoice == 1) { cout << "The distance between your two points is: " << TwopointDistance << endl; } else if (programChoice == 2) { cout << "The horizontal angle from the first point to the" " second point is: " << degreeAngle << endl; } else if (programChoice == 3) { cout << "The horizontal distance (in feet) the object" " traveled is: " << distanceFeet << endl; } else { cout << "The destination point is (" << destinationX << "," << destinationY << ")" << endl; // I need to display them here like (x,y) just unsure how } cout << endl << "Would you like to do another calculation (y/n)? "; cin >> again; } while (again == 'y'); return 0; } void displayMenu(void) { cout << endl; cout << "Choose from the following options: " << endl; cout << "(1) Compute the distance between two points" << endl; cout << "(2) Compute the horizontal angle of two points" << endl; cout << "(3) Compute the (horizontal distance (in feet)" << " that an object travels" << endl; cout << "(4) Compute the destination point" << endl; cout << "(5) Exit the program" << endl; } double engineerOne(double pointxI, double pointxII, double pointyI, double pointyII) { double TwopointDistance; TwopointDistance = sqrt(pow(pointxII - pointxI, 2) + pow(pointyII - pointyI, 2)); return (TwopointDistance); } double engineerTwo(double pointxI, double pointxII, double pointyI, double pointyII) { const double PI = 3.14159; double distanceX, distanceY, radianAngle, degreeAngle; distanceX = pointxII - pointxI; distanceY = pointyII - pointyI; if (distanceX > 0) { radianAngle = atan(distanceY / distanceX); } else if (distanceX < 0) { radianAngle = atan(distanceY / distanceX) + PI; } else if (distanceX == 0 && distanceY >= 0) { radianAngle = PI/2; } else { radianAngle = -PI/2; } degreeAngle = radianAngle * (PI / 180); return degreeAngle; } double engineerThree(double verticalAngleD, double velocityMile) { const double PI = 3.14159, FeetperMile = 5280, SecperHour = 3600, gravity = 32.172; double velocityFeet, verticalAngleR, distanceFeet; verticalAngleR = verticalAngleD * (PI / 180); velocityFeet = velocityMile * (FeetperMile / SecperHour); distanceFeet = pow(velocityFeet, 2) * sin(2 * verticalAngleR) / gravity; return distanceFeet; } //engineer four is the one I am having trouble with void engineerFour(double pointxI, double pointyI, double pointDistance, double angleDegree, double destinationX, double destinationY) { const double PI = 3.14159; double angleRadian, distanceX, distanceY; angleRadian = angleDegree * (PI / 180); distanceX = pointDistance * cos(angleRadian); distanceY = pointDistance * sin(angleRadian); destinationX = pointxI + distanceX; destinationY = pointyI + distanceY; //I get two destinations one for x and one for y } void getPoints(double& pointx, double& pointy) { cout << endl << "Please enter your x point: "; cin >> pointx; cout << endl << "Please enter your y point: "; cin >> pointy; } void custServiceOne(double& pointxI, double& pointxII, double& pointyI, double& pointyII) { cout << endl << "Please enter your first set of points: " << endl; getPoints(pointxI, pointyI); cout << endl << "Please enter your second set of points: " << endl; getPoints(pointxII, pointyII); } void custServiceTwo(double& pointxI, double& pointyI) { cout << endl << "Please enter your set of points: " << endl; getPoints(pointxI, pointyI); } void custServiceThree(double& verticalAngleD, double& velocityMile) { do { cout << endl << "Please enter your elevation angle: "; cin >> verticalAngleD; if (verticalAngleD <= 0 || verticalAngleD >= 90) { cout << endl << "Please input an angle between 0 - 90 degrees"; cout << endl << endl; } } while (verticalAngleD <= 0 || verticalAngleD >= 90); do { cout << endl << "Please enter the velocity: "; cin >> velocityMile; if (velocityMile <= 0) { cout << endl << "Please enter a positive velocity"; cout << endl << endl; } } while (velocityMile <= 0); } void custServiceFour(double& pointxI, double& pointyI, double& pointDistance, double& angleDegree) { cout << endl << "Please enter your set of points: " << endl; getPoints(pointxI, pointyI); do { cout << endl << "Please enter your distance: "; cin >> pointDistance; if (pointDistance <= 0) { cout << endl << "Please enter a positive distance"; cout << endl << endl; } } while (pointDistance <= 0); do { cout << endl << "Please enter your horizontal angle: "; cin >> angleDegree; if (angleDegree < 0 || angleDegree > 360) { cout << endl << "Please enter an angle between 0 - 360 degrees"; cout << endl << endl; } } while (angleDegree < 0 || angleDegree > 360); }``````

You do have, for example, a function
`void getPoints(double& pointx, double& pointy);`
Could you try to explain its details? What parameter types does it take?

Or more generally, what do you think the "by value" and "by reference" to mean?
I am probably explaining what I want to do wrong and I am sorry for that lol.

So generally I know that custServiceFour gets my information pointxI, pointyI, pointDistance and angleDegree and that sends it over to my engineerFour, but where I am having issues at is displaying the results for my engineerFour.

so I worked out the calculations:
pointxI = 5
pointyI = 8
pointDistance = 30
angleDegree = 45

I would get
destinationX = 26.21322
destinationY = 29.21319

generally in my main I want to display these points

 `` `` ``cout << "Your destination points are: (" << destinationX << "," << destinationY << ")"``

How would I pass the values that the engineer function calculates to the main function to display them here?

hope that makes more sense
Look at the declarations of custServiceFour and engineerFour. How do they differ?
Look at http://www.cplusplus.com/doc/tutorial/functions2/
Thanks for that keskiverto I went to look through my program and just threw the & in front of destinationX and destinationY and it worked.
Topic archived. No new replies allowed.