Solved Do i need to fix anythin in my code?

October 17, 2011 at 00:04:51
Specs: Windows XP
well I wanna do a question which i have to code a simple billing statement for a electric/power company and it supposed to be able to read from and write results to file originally but i was never taught that yet so I do not know how to manipulate files its basically instead of reading the kwh values from a file ..have the user enter end it..Here is the original question and here is what i did..any advice on additions or omissions would be greatly appreciated..
please dont say ur not helping me with homework because i did what i think is right and just looking for opinions and advice if necessary also its evening classes so i basically studying on my own.

Write a program that will calculate and print bills for the city power company. The rates vary depending on whether the use is residential, commercial or industrial. A code of R means residential use, a code of C means commercial use and a code of I means industrial use. Any other code should be treated as an error.
The rates are computed as follows:
R: $6.00 plus $0.052 per kwh used
C: $60.00 for the first 1000kwh and $0.045 for each additional kwh
I: Rate varies depending on the time of usage.
• Peak hours: $76.00 for first kwh and $0.065 for each additional kwh
• Off-peak hours: $40.00 for first 1000 kwh and $0.028 for each additional kwh
Your program should prompt the user to enter an integer account number, the use code type (type char) and the necessary consumption figures in whole numbers of kilowatt-hours. Your program should display the amount due from the user.

MY ANSWER-i tried to be as neat as possible sry if still scrappy and i use bloodshed dev-c++ btw its more spaced out in there:

#include <iostream>

using namespace std;

int main()

float resRate=0.0520 ,comRate=0.0450,indusRatePeek=0.0650,indusRateOpeek=0.0280,amtDue ;
int kwHours,acc,noHrs;
char c, C,I,i,R,r,Y,y,N,n,answerYoN,inputRate;//Upper and lower cases of rate codes


cout<<"Enter Account Number\n"; cin>>acc;
cout<<"Enter number of Kwhours\n"; cin>>noHrs;//Rince no way to read hours from account number
cout<<"Enter Rate < Residential (r) /Commercial (c) /Industrial (i) >\n"; cin>>inputRate; //Rate code input


if (inputRate=='c'||inputRate=='C')
if (noHrs>1000){amtDue=(noHrs-1000)*comRate+60;}//addition would be last so left out of brackets
else{amtDue=60.00;} cout<<"The Commercial amount due for account number "<<acc<<" is $"<<amtDue<<endl;
}//End of commmercial

else if (inputRate=='r'||inputRate=='R')
cout<<"The Residential amount due for account number "<<acc<<" is $"<<amtDue<<endl;
} //End of residential

else if (inputRate=='i'||inputRate=='I')
startover: cout<<"Any Peak Hours? <y/n>\n"; cin>>answerYoN;
if (answerYoN=='y'||answerYoN=='Y')
if (noHrs>1){amtDue=(noHrs-1)*indusRatePeek+76.00; cout<<"The Industrial amount due for account number "<<acc<<" at peak time is $"<<amtDue<<endl;}
else if (noHrs==1){ amtDue=76.00; cout<<"The Industrial amount due for account number "<<acc<<" for 1 hour at peak time is $"<<amtDue<<endl;}
}//End peektime
else if (answerYoN=='n'||answerYoN=='N')
if(noHrs>1000){amtDue=(noHrs-1000)*indusRateOpeek+40.00; cout<<"The Industrial amount due for account number "<<acc<<" at offpeek time is $"<<amtDue<<endl;}
else{amtDue=40.0; cout<<"The Industrial amount due for account number "<<acc<<" at offpeek time is $"<<amtDue<<endl;}
}//end offpeek
else{cout<<"Error: You can only enter y or n...\n"; goto startover;}//Testing my hand at goto perfectly
} //End of industrial

else cout<<"Error: Invalid Rate Code....\n";

//End Calculations

See More: Do i need to fix anythin in my code?

Report •

October 17, 2011 at 05:15:15
Shouldn't the rate of the first 1000 kwh for industrial be 76.00?

Report •

October 17, 2011 at 06:52:59
NO..only if 1 hour was used at off peak time if its more that 1 then its 76.00 for the first hour and every subsequent hour is 0.065...for industrial its suppose to ask you if the hours were peek time..if u answer yes then it will calculate the hours in at peektime rate if no then offpeek rate

Report •

October 17, 2011 at 07:36:26
✔ Best Answer
The offpeak rate is 40 for first 1000 kwh which is in line with commercial $60 for 1000 kwh. The $76 for 1 kwh is out of line.

Report •

Related Solutions

October 17, 2011 at 10:12:41
what exactly do you mean by out of line?.. do you think its how your seeing it on this site? because its clearer in text editor and i am getting the results i suppose to have..btw I always see that you should avoid using goto but it is so necessary in my opinion..i know it breaks nesting rules but do you know any other way to write a statement that does the same as the goto ?..oh and thanks a lot for reading

Report •

Ask Question