Thread: HELP I need to do this problem, can anyone help with the code

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    4

    HELP I need to do this problem, can anyone help with the code

    This is a problem that I have to complete for my programming class, i have a very limited understanding of C++ and was wondering if anyone would be able to help me out.
    Thank You

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Show your code.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    4
    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    using namespace std;
    
    
    // Global constants.
    // Your code should be written in such a way that it will
    // continue to work properly if these values are changed.
    const int minFoodPerDrop = 40,  // min food per drop
              maxFoodPerDrop = 60,  // max food per drop
              requiredFoodPerVillage = 100, // food each village must have
              maxVillages = 10,  // max number of villages
              tableEntries = 18,  // number of table entries
              landedInSea = -1;  // special value used to represent "landed in sea"
    
    
    // Simulates a single relief campaign and returns the number of drops
    // required to supply all of the villages.
    int simulateCampaign (int numberOfVillages) {
    
      int unitsReceived[maxVillages] = { 0 }, drops = 0,
          targetVillage, landingVillage;
    
      for (;;) {
    
        // Decide where the next drop should be targeted.
        targetVillage = pickTargetVillage (numberOfVillages, unitsReceived);
    
        if (unitsReceived[targetVillage] >= requiredFoodPerVillage) {
          // The village with the least amount of food has enough.
          // The campaign is complete.  Return the number of drops required.
          return drops;
        }
    
        // Work out where the drop will acually land.
        landingVillage = pickLandingVillage (numberOfVillages, targetVillage);
    
        if (landingVillage != landedInSea) {
          // The drop did not go into the sea.
          // Update the food received by the village where it landed.
          unitsReceived[landingVillage] += pickUsableUnits();
        }
    
        drops++;
    
      }
    
    }

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    And what are the problems with this code?
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    4
    its not complete, i dont know how to do the rest of the problem

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Try it and if got any problems, post here. And read homework policy.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  7. #7
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    Ok, so your pdf file breaks it down for you. You can do this one step at a time. Try implementing the pickLandingVillage function, it's pretty simple. Can you at least write the function without the implementation?

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Pretty appropriate user name it seems.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    The problem with the code is it's exactly what was provided by the professor. Consider a new major, bud.
    Last edited by rags_to_riches; 03-31-2011 at 09:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem uder LINUX (gcc) and same code work at Windows (DevC++)
    By miroslavgojic in forum C Programming
    Replies: 5
    Last Post: 11-24-2010, 10:05 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM