This is my first try at functions and I keep getting the same return of 1.
PLS help.
THX
/* This console apps will calculate the distance between 2 3D obects in 3D space.
This apps will request 2 sets of 3D coor5dinates (x,y,z) from user.
Once all values are recieved the program will call a function that I created to calculated the distance.
The function that I create must pass 6 float values(use const and pass by reference.
It must return a float value.*/
You never actually call calc_distance()
try creating a new var in main
double distance;
then call calc_distance()
distance = calc_distance(x1,x2,y1,y2,z1,z2);
//start with main()
int main(int argc, char *argv[])
{
SetConsoleTitle("Assignment 7 3D Distance By Shawn Cox "); //name console box
system("color 2b"); // set screen and font color
I'm not sure what grcunning was saying... but your first program only had one error: you didn't pass arguments to calc_distance. cout << " Distance = " << calc_distance << endl; should be cout << " Distance = " << calc_distance(x1, x2, y1, y2, z1, z2) << endl;
Here's why: Variables you declare only exist in the function in which you declare them. You declared all of those variables in main(), but you want to use them in calc_distance(). You already set up calc_distance() to receive all of those, but you didn't pass them.
Timaster,
I used that example because my prof has told us to never do any calculations or function calls in a cout statement. He says to always create a new variable, then use the variable in a cout statement.
I'm not sure what his reasoning is, so I just always do it that way
Oh, I see. That is good form, I guess, because it lets you see your function calls more clearly. If they're hidden in a bunch of cout << << << things, it could get confusing.
Sorry if it seems like I ignored your post, but I couldn't understand what you were saying, and I didn't want shawncox to be confused either :)
@grcunning: The reason for this will be that if you have multiple function calls and one of them causes a runtime exception it becomes alot more difficult than if they were on separate lines allocating to variables.