![]() |
|
#1
|
|||
|
|||
Pass by references?Hello, long time no post!
Anyways, I had some questions concerning pass by references. I want to create a list of functions that will be displayed in a menu. For example: Sample Run 1 Cylinder Menu 2 Sphere Menu 3 Cube Menu 4 quit 1 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 back to Main Menu 2 You have not defined a cylinder yet. Try again. 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 back to Main Menu 1 What is the radius and the height: 3 4 Done! 1 Define a cylinder 2 Surface Area 3 Circumference 4 Volume 5 back to Main Menu 4 The cylinder’s volume is 112. I'll go into detail about the cylander menu: Define a cylinder: asks the user for the radius and the height of the cylinder. Note that pass by reference must be used to reflect the change the user makes to these variables to be passed to the caller of this function: Cylinder Menu. Surface Area: if a cylinder is already defined since the last time the user entered into the Cylinder Menu, then this will compute and print the surface area of the defined cylinder. Refer to Sample Run section to see the scope of a defined cylinder. If a cylinder is not defined yet, it will give a proper error message. Circumference: if a cylinder is already defined since the last time the user entered into the Cylinder Menu, then this will compute and print the circumference of the defined cylinder. If a cylinder is not defined yet, it will give a proper error message. Volume: if a cylinder is already defined since the last time the user entered into the Cylinder Menu, then this will compute and print the volume of the defined cylinder. If a cylinder is not defined yet, it will give a proper error message. I'm having some trouble putting this all together. I'm just learning about pointers, and I know that pointers will be involved in this. Here is an example of the code I've made so far which includes the main menu, and the the cylander function (which works fine so far as I know) and the two functions to be called within the cylander menu that I am having trouble with. CPP / C++ / C Code:
Here is a copy/paste of this code in action: ----Hit any key to start. 1 Cylander Menu. 2 Sphere Menu. 3 Cube Menu. 4 Quit. 1 1 Define a Cylander. 2 Surface Area. 3 Circumference. 4 Volume. 5 Back to Main Menu. 1 Enter your radius and height:2 3 radius = 0 height = 0 1 Define a Cylander. 2 Surface Area. 3 Circumference. 4 Volume. 5 Back to Main Menu. I'm probally thinking the wrong direction for the pointers. Before I dig myself into a deeper hole, I figured I'd ask you guys for any insight on this problem. Thanks in advance, you all have helped me a lot in the past and I really appreciate it. It has made learning C a lot easier *so far*. I'd hate to push you guys, but please respond asap though, I'm in a time crunch at the moment Thank you very much once again |
|
#2
|
||||
|
||||
Re: Pass by references?Hi Cecil,
The error is in here: CPP / C++ / C Code:
You are getting the input from the user as x, and y. Look at the scanf again. Now, you are again overwriting it by using radius and height! Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: Pass by references?Alright, I changed that function to get rid of those statements, it now looks like this:
CPP / C++ / C Code:
Here is what now happens: ----Hit any key to start. 1 Cylander Menu. 2 Sphere Menu. 3 Cube Menu. 4 Quit. 1 1 Define a Cylander. 2 Surface Area. 3 Circumference. 4 Volume. 5 Back to Main Menu. 1 Enter your radius and height:2 3 radius = 37813564 height = 37813560 1 Define a Cylander. 2 Surface Area. 3 Circumference. 4 Volume. 5 Back to Main Menu. Yikes. Now I know that I'm far from discovering the solution to this. Once I fix this one function, I'll then need to find out how to: retreive this function's values and make the second function (cylander menu option 2) read the first function's output. Hmmm... |
|
#4
|
|||
|
|||
Re: Pass by references?I figured it out! If anybody is interested in knowing, here is the code. Once again I apologize for the horizontal heaviness!
CPP / C++ / C Code:
If you want the .c file, attached is the .zip file containing it. Turns out it was as simple as I thought. Functions are fun! ![]() |
|
#5
|
||||
|
||||
Re: Pass by references?Quote:
Simply stop using multiple tabs when a couple spaces would suffice. It will make your code easier to read. Reading this should help. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Belkin Laptop Cooler by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do you SAFELY pass hidden variables through merchant account payment screens? | mrsurrey | eCommerce / Merchant Account Forum | 4 | 03-Jul-2006 15:28 |
| References to base class to access derived class only members | mirizar | C++ Forum | 3 | 03-Dec-2005 20:40 |
| Cannot pass data between forms with enctype="multipart/form-data" attribute | MisterJingo | MySQL / PHP Forum | 0 | 05-Aug-2005 04:40 |
| Help wit my source code compiler errors | Krandygrl00 | C++ Forum | 1 | 06-Jun-2005 08:14 |
| vectors of references | mirizar | C++ Forum | 1 | 12-Apr-2005 02:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The