Consider a gas and electric bill that sets two levels of use as follows: Gas Electric Baseline Quantities 31 therms 238.7 kwh Baseline price $.504 /therm $.094 /kwh Over Baseline Price $.824 /therm $.133 /kwh Write a program that takes starting and ending readings for gas and electric meters and calculates charges to the nearest cent. Use one function to calculate charges for both gas and electric so as to eliminate duplicate calculations. I really do not understand what this is asking i dont need the code i just need an explaination.
this is what i have so far #include<iostream> double price( double amt, double baselineAmt, double baselinePrice, double oberBaseLinePrice); using namespace std; int main() { int gas, costofGas, amtGas; cout<<"enter the price for the gas"<<endl; cin>>gas; costofGas=price(amtGas, 31, .504, .824) cout<<price; return 0; }
Actually, the problem gives you the cost for both gas and electric. You need to determine the therms/kwhs used (by subtracting start value from end value for each. Basically you just make these up), then create a functions that can calculate the total price for either gas or electric from these values. In pseudo-code it might look like this: Get starting gas value Get ending gas value Get starting electric value Get ending electric value Compute gas charges Compute electric charges Your compute function might look something like this: ComputePrice(bool isElectric, startvalue, endvalue) If isElectric false // we're dealing with gas charges then therm = (end-start) overtherm = therm - 31 Price = therm * .504 + overtherm * 824 return the price You'll need to complete the Else part of the first if statement (isElectric) to handle the electric charges. This should at least get you started.
i'm using this in c++ so it would be the same thing basically right
Yes, what I showed you here is pseudo-code. It can be implemented in any language. You just need to use the right syntax; such as cout>> for C++.
Join our real-time social learning platform and learn together with your friends!