![]() |
|
#1
|
|||
|
|||
Help passing array data to other function.Hello, My name is michael i am 19 and studying a degree in audio technology. Im working on c++ atm and am having a bit of a problem! Hope you can help!
This is a basic program i have written which asks the user for 5 midi note values. these are then stored in an array and then used to find the highest value. I now wish to put the highest finiding part of my code into a seperate function, can someone help me as i havent got a clue where to start! I can send data to a function, but cant work out how to send array infomation and then return it. If you could explain simply and step by step it would be most appreciated as im new to c++ and i want to learn from the basics. Thank you. Mike CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
|
#1) don't use iostream.h use
CPP / C++ / C Code:
#2) main() is always and int, never a void #3) CPP / C++ / C Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
|||
|
|||
|
Thank you very much for such a quick reply, however i am still confused as to how to lay the function out in relation to my piece of coding, i dont want to ask you to do it for me, but i am still stuck. I have attempted to write the piece of code, but i have gotten bits wrong.
coulu you correct this for me in full? then i can break it down and understand how it works. thank you again! CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
|
Quote:
I added a couple of comments: CPP / C++ / C Code:
Regards, Dave |
|
#5
|
|||
|
|||
|
Wicked thanks alot. The comments werent final comments, i just put them in so i could sort the code out in my head! Im a newbie so it was helping me to seperate the differnent functions, your right tho they arent really needed!
I wonder if someone could point me in the right direction of thinking for my next problem.? I want to now include another function, which outputs every midinote with a value of 4. I can do this in the main block of code by doing the following... CPP / C++ / C Code:
I am getting confused as i cant work out what i will need to return, and which parts are getting sent to which bits! any help would be most appreciated Thankyou Michael |
|
#6
|
|||
|
|||
|
Quote:
If you want a function just to print out certain things, it doesn't have to return anything. (In other languages that is called a procedure, not a function, but in C there are only functions.) A function that doesn't return anything is given the type void CPP / C++ / C Code:
Where the function will be prototyped exactly as written: CPP / C++ / C Code:
Note that I changed things so that it is working on an array of int, not float. Use whatever you need the midi_note thingies to be, but be aware that if you are using floats, not all values may be represented exactly, and comparisons may not be valid (due to roundoff error). If you don't need floats, use ints. Regards, Dave |
|
#7
|
|||
|
|||
|
Thank you very very much, everyone who has helped! :-)
Mike |
|
#8
|
|||
|
|||
|
Quote:
Note the error in my example snippit! Make the function declaration look like the prototype: CPP / C++ / C Code:
Sorry 'bout that. Regards, Dave |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| [GIM] gim.h | dsmith | C Programming Language | 0 | 18-Jan-2005 09:48 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 05:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The