I am having trouble figuring out why I am getting an Unitialized Local Variable error in my code. The program calculates the charge associated with water depending on usage.
Here is the code:
The error shows
// Description: Calculate the water bill given the cubic feet of water used for Eureka Water Company, which charges the homeowner based on the following rules.
a. A flat rate of $15.00 for usage up to and including 1000 cubic feet.
b. $0.0175 per cubic foot for usage over 1000 cubic feet and up to and including 2000 cubic feet.
c. $0.02 per cubic foot for usage over 2000 cubic feet and up to and including 3000 cubic feet.
d. A flat rate of $70.00 for usage over 3000 cubic feet.
using namespace std;
void Read(int usage, double Charge);
void Print(double Charge);
void main ()
int x = 0;
x = (x + 1);
if(usage <= 1000)
Charge = 15.00;
else if (usage > 1000 && usage <= 2000)
Charge = 15.00 + (0.0175 * x);
else if (usage > 2000 && usage <=3000)
Charge = 15.00 + 17.50 + ( 0.02 * x);
Charge = 70.00;
void Read(int usage, double Charge)
// 1. Start
int usage = 0;
// 2. Prompt for Input
cout << "Enter Water Usage: ";
// 3. Read Input
cin >> usage;
// 4. Exit (Input returns via ref-param)
void Print(double Charge)
// 1. Start
// 2. Print Output
cout << "The charge is :" << Charge << endl;
// 3. Exit
I dug around on the forums and other C++ related sites and didn't find anything that would help fix the problem. Any help would be appreciated. Thanks.
2>c:\users\tyler\documents\cs104labtemplate.cpp(31): warning C4700: uninitialized local variable 'usage' used
2> lab6.vcxproj -> C:\Users\Tyler\Documents\Visual Studio 2010\Projects\lab6\Debug\lab6.exe
1> lab5.2.vcxproj -> C:\Users\Tyler\Documents\Visual Studio 2010\Projects\lab6\Debug\lab5.2.exe
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========