3 Replies - 230 Views - Last Post: 10 September 2012 - 02:51 AM Rate Topic: -----

#1 Weisguy216  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-September 12

Passing data from functions in C

Posted 09 September 2012 - 08:10 PM

Hi all, I have ran into a wall and was really hoping someone might be able to help me understand with an example.

I'm trying to write a program that simple enough just adds 2 number together from user input. The catch is I need 3 functions to do so.
Function1 (to be called from main) to ask for input of the first number and send it back to main
Function2 (to be called from main) to ask for input of the second number and send it back to main
Then the calculation is so be done in main
Function3 (to be called from main) will be used to display the data from the calculation

I know how to do this without functions but am currently unable to get the data to pass from any of the functions back to the main function.
I have read this chapter in my book (C by discovery, 4th edition, Foster & Foster) about 20 times and do not understand any better, I have also checked google and youtube.

If someone could maybe show an example of how to do this with 1 number I think I will be able to figure out the rest.

Is This A Good Question/Topic? 0
  • +

Replies To: Passing data from functions in C

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Passing data from functions in C

Posted 09 September 2012 - 08:22 PM

Show code that reflects your latest best attempt.

Quote

but am currently unable to get the data to pass from any of the functions back to the main function

What does this mean?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Passing data from functions in C

Posted 10 September 2012 - 02:45 AM

Read the tutorials in my signature..
Was This Post Helpful? 2
  • +
  • -

#4 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: Passing data from functions in C

Posted 10 September 2012 - 02:51 AM

Specifically, the Functions tutorials in his signature.

To pass data to/from functions, you need arguments and return values. You'll learn them there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1