Thanks in advance guys.
/* create and initialise total outside scope of
for loop so it is not reset every interation */
int totalP = 0;
//Perform loop iteration for b number of appliances
for (int b=0; b <arraySize; b++) {
//Ask user if they would like to use each appliance
cout << "\n Would you like to use " << a[b].getName() <<"? Please enter 1 for yes or 0 for no. " << endl;
bool ans; //Declare bool variable for answer to question
cin >> ans; //User input answer
if (ans==1){
//Ask user how many times they use appliance during a weekday
cout << "\n How many times would you like to use " << a[b].getName() << " during a weekday?" << endl;
int n; //Declare variable to store number of uses
cin >> n; //User inputs number of uses
//int calc1 = average power used by appliance * duration used * number of weekday uses
int calc1 = a[b].getAveragePower() * a[b].getDuration() * n;
//Ask user how many times they use appliance during a weekend day
cout << "\n How many times would you like to use " << a[b].getName() << " during a weekend day?" << endl;
int m; //Declare variable to store number of uses
cin >> m; //User inputs number of uses
//int calc1 = average power used by appliance * duration used * number of weekend day uses
int calc2 = a[b].getAveragePower() * a[b].getDuration() * m;
//Calculate total power use in Watts for weekend use
totalP = totalP + calc1 + calc2; // new total = old total plus new value for calc1 + calc2
//Print
cout << "\n Total energy use for weekend days is " << calc1 << endl;
cout << "\n Total energy use for weekdays is " << calc2 << endl;
}
}
return totalP; // Taken out of scope of for loop, so loop runs more than once
}
}
}
This post has been edited by JackOfAllTrades: 26 April 2010 - 12:51 PM
Reason for edit:: Fixed horrific indentation (sort of)

New Topic/Question
Reply




MultiQuote




|