![]() |
|
#1
|
|||
|
|||
Understanding functionsHello everyone,
I do not understand functions at all. I have read a lot of tutorials and I am still unclear as to exactly how functions work. I know what functions are, that they are a block of code that saves the programmer a lot of time so they dont have to rewrite repetitive code. Functions perform 1 task and returns 1 value, actually it's possible for them to return more than 1 value, but I am concentrating on understanding how they work. For example, can someone help me with this little simple problem. Can someone explain how this works and why: The C function is named printNumber and it has 3 arguments. The 1st argument should accept an integer number, the 2nd accept a floating point number, and the 3rd accept a double precision number. The body of the function should display the values of the data passed to the function when it is called. Write the main() function to call the printNumber() function. Use declaration statements to initialize the 3 numbers to be passed to the function. I will try to start and write what I know: [c] #include <stdio.h> Void printNumber (int a, float b, double c); int main () |
|
#2
|
|||
|
|||
|
Sorry...wait a second..I didnt mean to send this....I will complete the code
|
|
#3
|
|||
|
|||
|
[c]
#include <stdio.h> Void printNumber (int, float, double); int main () { int a; float b; double c; a=3 |
|
#4
|
|||
|
|||
sorrySorry for the repeated code....I am hitting a certain button and it's sending the reply and I dont know which one I am hitting.
CPP / C++ / C Code:
{{{Is this where the body of the function goes?}}} |
|
#5
|
||||
|
||||
|
I'm not going to write your program for you, but I'll give you a boost with this:
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
|
Thanks for the help Walter! It's starting to make sense the more I lookat the code. Are there any excellent tutorials out there that you know of that deals with functions? I have read a few tutorials, but there are probably a lot more out there. Are functions hard to grasp or is it me? I mean, do a lot of people have trouble learning functions? I dont know why it's taking me a long time to figure it out. I know functions are important and I need to learn them. do you have any suggestions in learning them? These questions are for whoever can help. Thanks......tommy
|
|
#7
|
|||
|
|||
|
Hey Tommy,
You may want to check this tutorial out: http://www.cplusplus.com/doc/tutorial/tut2-2.html One of the great advantages of functions is that they allow you to break your program down into sub-problems (this is called top-down design). This is advantageous because it allows you to work on individual problems without getting overwhelmed and confused with an entire problem at once. Maybe it would be helpful to think of functions as sub-programs, or mini-programs that perform a very specific task. If you were having more problems with the syntax of a function and how it works, the tutorial link above should be able to help. Regards, Pan Thomakos |
|
#8
|
||||
|
||||
|
Quote:
Quote:
CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
|
Thanks a lot guys for the help. I really appreciate it. I hope I can get really good at writing functions because I have a big program that I need to write and it's a hard one and it involves a lot of functions. I seriously doubt I will be able to do it on my own. If I have trouble, then I will post the problem and see if I can get some help. I am not expecting anybody to write it for me because I won't learn that way. However, I might need someone to help start it for me or look over the code. You all have helped me a lot and it's obvious you know how to program. I took the Visual basic and advanced class and I know how to program a little in VB, but C is totally different. There are a lot of similarities and functions are one of them. I will keep in touch :-)
By the way, what does this mean. I need to write a C program using the getchar(), toupper(), and putchar() functions that echo back all letters entered in their uppercase form? The program should terminate if the suer types in either an S or a s. Does this mean that if a user types in any letter, except for the S and s, the uppercase form is displayed? Or does the user only type in an uppercase letter and the uppercase letter is displayed again? I am only trying to figure out what this program needs to do. I have never used these functions before, but I will experiment. I think I will use a Do/while loop with an If Else statement. Take care guys and have a great week!! Tommy |
|
#10
|
||||
|
||||
|
Well, as far as I know, the word terminate is a synonym for end. Since you can't go any further than the end, I'm thinking he wants the program to STOP once you read the letter S in upper or lower case. Why dont you just ask him?
__________________
-Aaron |
Recent GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing Pointers To Pointers in Functions | elumira | C Programming Language | 8 | 05-Mar-2004 21:23 |
| Calling functions within a function | spudtheimpaler | C Programming Language | 5 | 02-Mar-2004 08:02 |
| New to C...need help calling functions | rbeierle | C Programming Language | 3 | 10-Feb-2004 18:46 |
| Need C++ help with functions | EvilIce | C++ Forum | 2 | 01-Dec-2003 16:04 |
| need help to define a class in C++ | yannoush | C++ Forum | 7 | 09-Sep-2003 00:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The