Hello TangentJay,
Now that everyone has gone off and ignored the original problem.
First off it is always a good idea to initialize your variables.
1 2 3
|
int m{}, i{}, kwh{};
string tde;
float sum1{}, sum2{}, temp1{}, temp2{};
|
This makes it very easy and you do not have to worry about the garbage value of the uninitialized variable. And for a variable like "sum" or "total" you would not want to start with a value of "-107374176.0" for a float or "-9.2559631349317831e+61" for a double and then do a (+=). You are more likely to just get a result that is a bit less small.
Next problem I noticed is:
temp1 = 9.95;
. Here, unless noted otherwise, the "9.95" is considered a double and you are trying to put the larger double into the smaller float. The compiler will give you a warning. When the code is executed it will basically chop off the part of the double that does not fit into the float. Sometimes the last number of the float will be rounded up before the data from the double is lost.
These days the preferred floating point type is a double. There is still the need for a float in some programs. You may be saving on storage space and ther are still some functions that require a float type variable.
Not initializing your variables when defined it the reason for the run time error when "temp2" never receives a proper value.
When I got the program to run I got this first output:
Enter number of months:
3
Enter your tde:
asdf
Enter 1 month usage(kwh): 2500
|
As
agent max noted I do not know what a "tde" is, actually I do, but do not remember what the letters stand for, so it would be better to spell it out. Unless you are sure that every user knows what "tde" stands for.
As a user not familiar with "tde" and the power companies in the area I would go with
dutch's example if using a menu to choose a company before I would let a user enter something like "TEXAS-NEW MEXICO POWER". I have come to the conclusion that on any given day any given user
WILL find a way to break your program without even trying no matter how much you try to anticipate any problems. The first thing that comes to mind is that you are expecting capital letters, but some user will enter that name in lower case letters and then nothing will match.
When the program properly I got this output:
Enter number of months: 3
Enter your tde: TEXAS-NEW MEXICO POWER
Enter 1 month usage(kwh): 2000 // >--- To me "Enter usage for month 1 (in kwh): " makes more sense. Its up to you.
Charges for 1 month based on charges specified in EFL: 9.987
Charges for 1 month in TEXAS-NEW MEXICO POWER: 104.492
Total charge for 1 month is: 114.479
Enter 2 month usage(kwh): 2500
Charges for 2 month based on charges specified in EFL: 10.027
Charges for 2 month in TEXAS-NEW MEXICO POWER: 128.653
Total charge for 2 month is: 138.679
Enter 3 month usage(kwh): 2250
Charges for 3 month based on charges specified in EFL: 10.027
Charges for 3 month in TEXAS-NEW MEXICO POWER: 116.572
Total charge for 3 month is: 126.599
Charges for 3 months based on charges specified in EFL: 30.041
Charges for 3 months in TEXAS-NEW MEXICO POWER: 349.717
Total charge for 3 months is: 379.758
|
That should give you something to work with.
Andy