programming in C homework help

Live forum: http://forum.freeipodguide.com/viewtopic.php?t=77596

Driscollv2

14-10-2008 18:25:35

I am trying to get the switch to work so that when you enter an 'R' or 'r' it comes up under the variables I have for it.


#include <stdio.h>

#define PER_KWH_USED 0.052 /li residential kilowatt per hour used li/
#define ADD_KWH 0.045 /li commercial additional kilowatt per hour used li/
#define PEAK_KWH 0.065 /li industrial peak additional kilowatt per hour used li/
#define OFF_PEAK_KWH 0.028 /li industrial off-peak additional kilowatt per hour used li/

/li function prototypes li/

double comp_r_due(int res_kilowatt_hrs);
double comp_c_due(int com_kilowatt_hrs);
double comp_i_due(int peak_hrs, int off_peak_hrs);

int
main(void)
{
int acct_num; /li input - account number li/
char code; /li input - type of service li/
int res_kilowatt_hrs; /li input - total residential kilowatt hours li/
int com_kilowatt_hrs; /liinput - total commercial kilowatt hours li/
int peak_hrs; /li input - industrial peak hours li/
int off_peak_hrs; /li input - industrial off peak hours li/
double r_due; /li output - residential amount due li/
double c_due; /li output - commercial amount due li/
double i_due; /li output - industrial amount due li/

/li display user instructions li/

printf("Enter the account number > ");
scanf("%d", &acct_num);
printf("Enter the code R - Residential n C - Commercial n I - Industrial");
scanf("%c", &code);

/li check for upper and lower case li/

switch (code)
{
case'R'
case'r'
printf("Enter the kilowatt-hours > ");
scanf("%d", &res_kilowatt_hrs);
printf("nnn");
printf("Residential use");
printf("Account Number %d",acct_num);
printf("kilowatt-hours %d",res_kilowatt_hrs);
printf("Amount due $ %2.f",r_due);
break;

case'C'
case'c'
printf("Enter the kilowatt-hours > ");
scanf("%d", &com_kilowatt_hrs);
printf("nnn");
printf("Commercial use");
printf("Account Number %d",acct_num);
printf("kilowatt-hours %d",com_kilowatt_hrs);
printf("Amount due $ %2.f",c_due);
break;

case'I'
case'i'
printf("Enter the peak kilowatt-hours > ");
scanf("%d", &peak_hrs);
printf("Enter the off-peak kilowatt-hours > ");
scanf("%d", &off_peak_hrs);
printf("nnn");
printf("Industrial use");
printf("Account Number %d",acct_num);
printf("Peak kilowatt-hours %d",peak_hrs);
printf("Off-peak kilowatt-hours %d",off_peak_hrs);
printf("Amount due $ %.2f",i_due);
break;


} /li switch li/

return(0);

}

double comp_r_due(int res_kilowatt_hrs)

{

double r_due;

r_due = 6 + PER_KWH_USED li res_kilowatt_hrs;

return (r_due);

}

double comp_c_due(int com_kilowatt_hrs)

{

double c_due;

if (com_kilowatt_hrs <= 1000)
c_due = 60;

else if (com_kilowatt_hrs > 1000)
c_due = 60 + ADD_KWH li com_kilowatt_hrs;

return (c_due);
}

double comp_i_due(int peak_hrs, int off_peak_hrs)


{
if (peak_hrs <= 1000)
return(76);


if (off_peak_hrs <= 1000)
return(40);
else
return(((peak_hrs-1000) li PEAK_KWH + 76) + ((off_peak_hrs-1000) li OFF_PEAK_KWH + 40));

}