Я думаю, вы могли бы сделать следующее с тройными переменными:
#include <iostream>
using namespace std;
int main ()
{
double watts_ac, watts_tv, watts_wa;
double hours_per_day_ac, hours_per_day_tv, hours_per_day_wa;
double watt_hours, dollars_per_wh;
dollars_per_wh= .00008;
cout << " How many Watts for the Air conditioner? ";
cin >> watts_ac;
cout << " How many hours/day do you run the Air Conditioner? ";
cin >> hours_per_day_ac;
cout << "How many Watts for the Television? " ;
cin >> watts_tv;
cout << "How many hours/day do you run the Television? " ;
cin >> hours_per_day_tv;
cout << "How many Watts for the Washer? " ;
cin >> watts_wa;
cout << "How many hours/day do you run the Washer? " ;
cin >> hours_per_day_wa;
watt_hours = (watts_ac * hours_per_day_ac + watts_tv * hours_per_day_tv + watts_wa * hours_per_day_wa) * 30; //I'm not sure what this 30 factor is due to though.
cout << "You have used " << watt_hours << " Watts-Hours of electricity." << endl;
}
или просто агрегировать данные:
#include <iostream>
using namespace std;
int main ()
{
double watts, hours_per_day_ac, watt_hours, dollars_per_wh;
dollars_per_wh= .00008;
cout << " How many Watts for the Air conditioner? ";
cin >> watts;
cout << " How many hours/day do you run the Air Conditioner? ";
cin >> hours_per_day;
watts_hours = watts*hours_per_day;
cout << "How many Watts for the Television? " ;
cin >> watts;
cout << "How many hours/day do you run the Television? " ;
cin >> hours_per_day;
watts_hours += watts*hours_per_day;
cout << "How many Watts for the Washer? " ;
cin >> watts;
cout << "How many hours/day do you run the Washer? " ;
cin >> hours_per_day;
watts_hours += watts*hours_per_day;
watt_hours *= 30; //I'm not sure what this 30 factor is due to though.
cout << "You have used " << watt_hours << " Watts-Hours of electricity." << endl;
}