Definitely wrote my own code. I've been at it for a while now and it's driving me mad. I'm just looking for some help where i'm going wrong.
I've had a look at my code and i've changed billOff and billPeak to be doubles, put some braces into my last if/else (don't think it matters in this case). There's definitely something up in this if/else though I can't see it
Code:
#include <stdio.h>
int main()
{
char code;
double account,consump, bill, peak, off, billPeak, billOff;
printf("Enter account no.: ");
scanf("%d", &account);
printf("Enter consumption in kwh: ");
scanf("%d", &consump);
printf("Code: ");
while((code=getchar()) && code == '\n');
if (code=='R' || code=='r' ){
printf("\n\nAccount no: %d\n", account);
bill = consump * 6.052;
printf("Bill %f\n", bill);
}
else if (code=='C' || code=='c' ){
printf("\n\nAccount no: %d\n", account);
if (consump<=1000)
bill = 60;
else bill = (((consump-1000)*0.045)+60);
printf("Bill %f\n", bill);
}
else if (code=='I' || code=='i' ){
printf("Enter Peak: ");
scanf("%d", &peak);
if (peak<=1000)
{
billPeak = 76;
}
else
{billPeak = (((peak-1000)*0.045)+60);
}
printf("Enter Off Peak: ");
scanf("%d", &off);
if (off<=1000)
{billOff = 40;
}
else {billOff = (((off-1000)*0.028)+40);
}
printf("\n\nAccount no: %d\n", account);
printf("Bill %f\n", billPeak+billOff);
}
return 0;
}