Getting Obscure Numbers For End Result! HELP!
I have this program that I wrote to calculate electricity rates for class. The only problem was when I ran it I got a weird number. I started changing some things but I still can't get it to work. If anyone could just take a look at it and tell me how to correct it that would be great. Thanks!
PS: I think that the values in the Calculation function are not carrying over to the Main Function, thus not outputting the right values. Not sure how to go about it then.
#include <iostream>
#include <cmath>
using namespace std;
int Instruction();
int Valid();
double Calculation();
int BillPrint();
int Instruction()
{
cout<<"Welcome to the Bill Calculation Program."<<endl;
cout<<"Step 1:Enter Customer Name"<<endl;
cout<<"Step 2:Enter Account Number"<<endl;
cout<<"Step 3:Input User Code"<<endl;
cout<<"Step 4: Input kwh in residential users field and commerical while the commerical one should use off-peak and peak hours."<<endl;
cout<<"Step 5:Print out the bill."<<endl;
return 0;
}
int Valid(char UCode)
{
if (UCode =='R')
return 1;
else if (UCode =='C')
return 1;
else if (UCode =='I')
return 1;
else
cout<<"Invalid User Code. Restart program."<<endl;
return 0;
}
double Calculation(char UCode, float Rkwh, float Ckwh, float Pkwh, float OPkwh)
{
float Bill;
float OPBillI;
float PBillI;
if(UCode =='R')
{
cout<<"Please enter number of kwh used: ";
cin>>Rkwh;
/* return Rkwh;*/
Bill = (.052 * Rkwh) + 6.00;
/*return Bill;*/
}
else if(UCode =='C')
{
cout<<"Please enter amount of kWh used: ";
cin>>Ckwh;
/*return Ckwh;*/
if(Ckwh<=1000)
Bill=60.00;
/*return Bill;*/
if(Ckwh>1000)
Bill=60.00+((Ckwh-1000)*.045);
/*return Bill;*/
}
else if(UCode =='I')
{
cout<<"Please Enter Peak Hour Usage(8AM to 5PM): ";
cin>>Pkwh;
cout<<"Please Enter Off-Peak Usage(5PM to 8AM): ";
cin>>OPkwh;
/*return Pkwh;*/
if(Pkwh<=1000)
PBillI=76.00;
if(Pkwh>1000)
PBillI=76.00+((Pkwh-1000)*.065);
if(OPkwh<=1000)
OPBillI=40.00;
if(OPkwh>1000)
OPBillI=40.00+((OPkwh-1000)*.028);
Bill= PBillI+OPBillI;
}
else
cout<<"Invalid Entry."<<endl;
return Bill;
return Rkwh;
return Ckwh;
return Pkwh;
return OPkwh;
}
int BillPrint(float Bill, float Rkwh, float Ckwh, float Pkwh, float OPkwh, char UCode, int AccountNum)
{
cout<<"The Random Electric Company"<<endl<<"123 Tasselhoff Road"<<endl<<"Orinda, CA 94563"<<endl<<endl;
cout<<"--------------------------"<<endl;
cout<<"Account Number: "<<AccountNum<<endl;
if(UCode =='R')
{
cout<<"Total kwH used: "<<Rkwh<<endl<<"Amount Due: "<<Bill<<endl;
}
else if(UCode =='C')
{
cout<<"Total kwH used: "<<Rkwh<<endl<<"Amount Due: "<<Bill<<endl;
}
else if(UCode =='I')
{
cout<<"Total Peak Usage: "<<Pkwh<<endl<<"Total Off-Peak Usage: "<<OPkwh<<endl<<"Amount Due: "<<Bill<<endl;
}
else
cout<<"Invalid Code. Restart Program."<<endl;
return 0;
}
int main()
{
int AccountNum;
char UCode;
Instruction();
cout<<"Please enter account number. ";
cin>>AccountNum;
cout<<"Please enter User Code. ";
cin>>UCode;
Valid(UCode);
Calculation();
BillPrint();
system("pause");
cout<<"Program Terminated."<<endl;
return 0;
}

