Thread: Programming assignment help!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Not a bad start...

    This is an incomplete answer... I'm not at my compiler...

    void program (); - When you put this inside main, you leave out the return type (void), and you place it in the sequence where you "call" it.

    // Get user input
    program(); // Go to program() function and do it!
    // Show results
    // Ask to loop

    And... Your function needs a return type... you want it to return a cost or something, you don't want void in this case. And, you need parameters... something like...

    // Function prototype
    float program(float Area, float CostPerInch)

    // Call program() function
    Cost = program(Area, CostPerInch);

    Remember variable "scope". The variables aren't avaliable inside your function unless they are passed-in as paramaters (arguements?) You can define local variables inside the function, PI for example. And, you could ask for user input inside the function... if that's what you wanted to do.


    Start "small". Write the body of your main program first, compile and test it, then add a little and repeat. This makes it much easier to locate errors. You can also write "empty" functions to test compile.

    [EDIT]
    A function is (sort-of) like a detour. Go over there and do something. Then, come back here continue... maybe take some numbers with you, and maybe bring one number back. Now, just so I don't get flamed... Later, you'll learn that sometimes these "numbers" may be references or pointers.
    Last edited by DougDbug; 03-13-2003 at 06:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM