Thread: 2-d monte carlo integration help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    48
    Okay, sweet! I'm slowly working on it (studying for other things aswell, very loaded this weekend) so expect an update sometime this evening. But there is one question I have, what do I do with main? That's something that was really confusing me, it never mentions main... I know for example, that if a variable need not be static, then I can put it in there... So one idea I have id that my main should have world variables, and also the final print out statements?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by jsuite View Post
    Okay, sweet! I'm slowly working on it (studying for other things aswell, very loaded this weekend) so expect an update sometime this evening. But there is one question I have, what do I do with main? That's something that was really confusing me, it never mentions main... I know for example, that if a variable need not be static, then I can put it in there... So one idea I have id that my main should have world variables, and also the final print out statements?
    Programs in C usually have 3 functional parts - Input, Calculation/s, and Output. In a small program, all three can fit nicely inside main(), but on larger programs, you may need one or more functions, for each of these parts of the program.

    Try thinking of main() as the starting point for your program, and the subsequent point of return. It could be just two lines of code, or several blocks of code.

    Since several other functions have specific requirements, I'd get them set up first - even if the requirements are not coded, but just listed in notes:
    Code:
    //?? ThrowDarts(unknown) {
     /*    gets unsigned long N for number of darts to be thrown from the user */ //kind of thing.
    
       //return??
    //}
    Save the contents of main() and other non-required (by the assignment) functions, until later. You can be much more flexible with them. Use them for "glue", to make the logic flow OK.

    In general, list the requirements, inside the required functions (if known), but put off all the details that are not important, until you get the core logic flowing.

    Once the core logic is working, then add in the details. Saves a lot of time.

    Global variables (which have program-wide scope), are listed above main(). They can be useful, but are a negative on the whole purpose of functions (which is to encapsulate a portion of the program). Use them VERY sparingly, if at all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Monte Carlo Simulation Optimization
    By Phys10 in forum C++ Programming
    Replies: 5
    Last Post: 08-02-2010, 04:09 AM
  2. Help with C Monte Carlo
    By shaunmikex in forum C Programming
    Replies: 7
    Last Post: 03-21-2010, 05:11 PM
  3. Monte Carlo reliability program - SegFault :(
    By Kibble Fat in forum C Programming
    Replies: 7
    Last Post: 12-15-2009, 02:41 PM
  4. Problem with Monte Carlo(integration by rejection)
    By dionys in forum C Programming
    Replies: 9
    Last Post: 04-07-2004, 09:53 AM
  5. monte carlo methods
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 09-05-2001, 11:29 PM