![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
Quote:
:o
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#12 |
|
Newbie
Join Date: May 2006
Posts: 12
Rep Power: 0
![]() |
Wow thanks guys. I haven't had time to read all this since I am at work at the moment. To Dewei, yes, in Algebra we did things like f(x) 2x+3 where you had to find x= a number.
Ill read all this tonight. Thanks for the help everyone. |
|
|
|
|
#13 |
|
Newbie
Join Date: May 2006
Posts: 12
Rep Power: 0
![]() |
Ok reading over things... let me try. The syntax will be off cause im new to this but still...
#include <iostream> int addtwo(int) int main() { cout << "Enter a number" << endl; int firstnumber; cin >> firstnumber; cout << "That number plus 2 is " << addtwo(firstnumber) << endl; } int addtwo(int numberinput) { return numberinput + 2; } Right? |
|
|
|
|
#14 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
Looks good, although the function prototype should have a semi-colon after it and you should declare the scope of cin, cout, and endl (either prepend std:: to all of them, or put using statements after the #include). By the way, when you post code here, put it in [code] tags and it'll preserve formatting and keep it easier to read for everyone.
![]() |
|
|
|
|
#15 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
What Jim said. You wanna join the club and get the free goodies, read the freakin' rules.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
#16 | |
|
Newbie
Join Date: May 2006
Posts: 12
Rep Power: 0
![]() |
Quote:
I came here for help, I didn't ask for a childish remark for a 90 year old man on Viagra. Thank you. |
|
|
|
|
|
#17 |
|
Programming Guru
![]() |
Wow, that was an excellent explanation of functions Jessehk. I'm surprised. If only the tutorial I read when I was first introduced to functions a while back was that well explained. The tutorial I read before seemed to assume I had learned Functions in math before. However, you explained it in a realistic context.
![]() Perhaps you could have explained more about the purpose of void though. ![]() |
|
|
|
|
#18 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
The purpose of 'void' is to explicitly state that NOTHING is in play. This precludes trying to decide if something is missing or left out or if its absence is intended.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
#19 |
|
Programming Guru
![]() |
However... I understand that void is generally bad practice. I've learned to return (0); instead of voiding a function. Is there any information I am missing, or different sides to that rule of thumb?
|
|
|
|
|
#20 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|