Jump to content

C Programming - Parameter


WhenKittensATK

Recommended Posts

I realize that's not all the code but is there a reason outputresults returns a double? if it is simply printing out the parameters it's passed why not just return a void. Or if you are returning something just to show it ran correctly why not an int?

 

anyways, glad you figured it out.

Share this post


Link to post
Share on other sites

First off, main should be above all other functions (especially since you're calling those functions from main).

 

Second, the function should have a return type of void since it does nothing other than print out junk and return nothing.

 

Last - just think about what variables your function will need and pass them by value (like you did above). Guessing randomly is no way to learn how to program.

Share this post


Link to post
Share on other sites

Although it's not a huge issue in this case, your outputResult function should have been a void as stated above. It doesn't return any values, why should it be a double? Also, there's no issue with putting you function above main, but good formatting has you declare the functions above main, but fill them in below main. You'd have:

 

double outputResult(blah blah)

 

main()

{

blah blah

}

 

double outputResult(blah blah)

{

blah blah

}

 

Again, not important here, but you should pass the values by reference from main into outputResult. In this program it doesn't matter, but in larger programs it's a way to conserve memory space.

Share this post


Link to post
Share on other sites

I started this assigment 1hour before it was due, the lecture it self was over an hour. I really didn't want to spin any time doing it. Thats why I randomly plugged it in. I had it void at first, not sure why I changed it.

 

Note this is only a concepts class and he really didn't go into detail. When he was doing the lecture he just did the main function first, then decomposed all his variables in functions above the main function. Thank you for letting me know that functions go in the main() then declaring it above.

 

Programming is trail and error, plugging thing randomly some times works and you learn how to do it from that. Newbie programmers aren't going to get their programs running 100% on the first write down. Tweaks will be made, editing will be done. I just didn't have any time for that since I alreadly passed the the due time which was 11pm and I turned it in about 12:45 am.

Share this post


Link to post
Share on other sites

Note this is only a concepts class and he really didn't go into detail. When he was doing the lecture he just did the main function first, then decomposed all his variables in functions above the main function. Thank you for letting me know that functions go in the main() then declaring it above.

The functions don't go in main, they were saying to put them below main, big difference. Just trying to help out the terminology.

 

I hope you don't think we're being punks either. We really are trying to help because these things are important. It's good to get good techniques early on rather than trying to change things later.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...