Hello hilal1990,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
That is a good start, but I have some suggestions.
1 2
|
double oldYearRate = 9.92; // Rate of KWHr in 2001
double newYearRate = 20.34; // Rate of KWHr in 2015
|
These are fixed numbers that should not change and the names do not reflect what they are. Since you do not want to change these numbers it would be better to write it this way. And the variable names should better reflect what they are:
1 2 3
|
constexpr double startRate = 9.92; // Rate of KWHr in 2001
constexpr double endRate = 20.34; // Rate of KWHr in 2015
double newearRate{}; // <--- initializes to zero. Always initialize your variables.
|
The first two lines can not be changed by the program now. If you do the compiler will tell you that you did something wrong.
In addition to defining "newYearRte" you will need some other variables to use in your program. Always initialize your variables to something. Just defining
char again;
will cause the while loop you have to fail before it can ever run because "again" has no value at this point, just storage space.
char again{ 'Y' };
will work better.
These lines:
1 2 3
|
newYearRate = (1 + averageRateIncrease) * oldYearRate;
cout << "Enter Rate of Increase Guess (in %): ";
cin >> oldYearRate;
|
Should be inside the while loop.
These lines
1 2
|
cout << "The Current rate would be: " << newYearRate << " cents/KWHr" << endl;
cout << "The desired rate should be: " << newYearRate << " cents/KWHr" << endl;
|
May be useful inside the while loop also.
Just some thoughts for now. I will have to load up what you have and see how it works.
Hope that helps,
Andy