I cannot get this switch to work for some reason. I run compile and enter the account number and when I try to enter an 'r' or 'R' it does not run the functions I have in place. I am taking an intro class and can usually figure this stuff out, but I am completely lost on this one. I used bold to highlight the switch area.
Code:
#include <stdio.h>
#define PER_KWH_USED 0.052 /* residential kilowatt per hour used */
#define ADD_KWH 0.045 /* commercial additional kilowatt per hour used */
#define PEAK_KWH 0.065 /* industrial peak additional kilowatt per hour used */
#define OFF_PEAK_KWH 0.028 /* industrial off-peak additional kilowatt per hour used */
/* function prototypes */
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; /* input - account number */
char service; /* input - type of service */
int res_kilowatt_hrs; /* input - total residential kilowatt hours */
int com_kilowatt_hrs; /*input - total commercial kilowatt hours */
int peak_hrs; /* input - industrial peak hours */
int off_peak_hrs; /* input - industrial off peak hours */
double r_due; /* output - residential amount due */
double c_due; /* output - commercial amount due */
double i_due; /* output - industrial amount due */
printf("Enter the account number > ");
scanf("%d", &acct_num);
printf("Enter the code R - Residential \n C - Commercial \n I - Industrial\n\n ");
scanf("%c", &service);
switch (service)
{
case 'R':
case 'r':
printf("Enter the kilowatt-hours > ");
scanf("%d", &res_kilowatt_hrs);
printf("\n\n\n");
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("\n\n\n");
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("\n\n\n");
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;
} /* switch */
return(0);
}