d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need A Block Of Code..
Add Reply New Topic New Poll
Member
Posts: 18,191
Joined: May 31 2010
Gold: 149.27
Apr 26 2013 02:19pm
Description;
3. public static void processDonations()
a. Should set totalCash and totalFood to 0 so that it does not accumulate with multiple runs.

b. Should include a for loop that runs 6 times and includes the following:
i. A calculation for accumulating totalCash
ii. A calculation for accumulating totalFood

c. Should set maxCash to cashDonations[0]

d. Should set maxFood to cashDonations[0]

e. Should include a for loop that runs 6 times and includes the following:
i. An if statement that determines maxCash and bestSiteCash
ii. An if statement that determines maxFood and bestSiteFood



My code as it stands;

public static void processDonations()
{
Scanner input = new Scanner(System.in);
totalCash = 0;
totalFood = 0;

for (int i = 0; i < 6; i++)
{

maxFood = cashDonations
maxFood = cashDonations};


Need help with the rest of b and e; pm me, i can pay.
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Apr 26 2013 02:32pm
b.
Code
for ( int i = 0; i < 6; i++ ) {
     totalCash += cashDonations[i];
     totalFood += foodDonations[i];
   }


e.
Code
int maxCash = cashDonatios[0]; //This part is c
   int maxFood = foodDonations[0]; //This part is d
   for ( int i = 0; i < 6; i++ ) {
     if ( foodDonations[i] > maxFood ) {
       maxFood = foodDonations[i];
     }
     if ( cashDonations[i] > maxCash ) {
       maxCash = cashDonations[i];
     }
   }


What is bestSiteCash and bestSiteFood?


I also fixed c and d, and added comments for them

This post was edited by labatymo on Apr 26 2013 02:34pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll