Problem on working on my billing project.

Hi, i having a problem that i do not know where i gone wrong with my project. my project is on billing(hand phone bill). MY problem is that once i compute the bill of the user, all the 4 plan(A, B, C & D) prices being display on the output. may i know why is this so? i uses if-else statement for each plan but it seem not working in the right way as it suppose to be. can anyone help me with it??


#include <stdio.h>
#include <string.h>
void main()
{
int tel[99]={0}, choice, pos;
int sf, ctt, cls;
int ttt[99],tls[99], tos[99];
char name[99][30]={" "}, IC[99][9]={" "}, sp[4]={'A', 'B', 'C', 'D'};
float gprs[99]={0};
float ttc1, ttc2, lsc1, lsc2, osc, gtc, st1, st2, gst1, gst2, tb1, tb2;

while(choice!=4)
{
printf("\nShingTel ONLINE Billing SYSTEM");
printf("\n******************************");
printf("\n(1) Input of Customer Data");
printf("\n(2) Computation of Bill");
printf("\n(3) Display Bill");
printf("\n(4) Quit");
printf("\nEnter Choice:");
scanf("%d", &choice);
switch(choice)
{
case 1: printf("\n\tInput of Customer Data");
printf("\n\t==============================================");

printf("\n\tPlease enter account number:");
scanf("%d", &pos);

printf("\n\tPlease enter name:");
flushall();
gets(name[pos]);

printf("\n\tPlease enter IC number:");
scanf("%s", &IC[pos]);
flushall();

printf("\n\tPlease enter telephone no:");
scanf("%d", &tel[pos]);
flushall();

printf("\n\tPlease enter Subscription Plan:");
scanf("%c", &sp[pos]);
flushall();

printf("\n\tPlease enter Total Talk Time (in minutes):");
scanf("%d", &ttt[pos]);
flushall();

printf("\n\tPlease enter Total Local SMS:");
scanf("%d", &tls[pos]);
flushall();

printf("\n\tPlease enter Total Overseas SMS:");
scanf("%d", &tos[pos]);
flushall();

printf("\n\tPlease enter GPRS Traffic (in MB):");
scanf("%f", &gprs[pos]);
flushall();
printf("\n\t==============================================");
break;

case 2: printf("\n\tComputation of Bill");
printf("\n\t*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-");

printf("\n\tWhich account to computated:");
flushall();
scanf("%d", &pos);

if(sp[pos] == 'A' || sp[pos] == 'a');
{
sf = 22;

if(ttt[pos] <= 100)
{
printf("\n\n");
ttc1 = ttt[pos] * 0.16;
printf("Talk time cost is:%.2f\n", ttc1);
}
else
{
ctt = ttt[pos] - 100;
ttc2 = ctt *0.16;
printf("Talk time cost is:%.2f\n", ttc2);
}

if(tls[pos] <= 100)
{
lsc1 = tls[pos] * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc1);
}
else
{
cls = tls[pos] - 100;
lsc2 = cls * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc2);
}

osc = tos[pos] * 0.15;
gtc = gprs[pos] * 0.50;

printf("Overseas SMS Cost is:%.2f\n", osc);
printf("GPRS Traffic Cost is:%.2f\n", gtc);

st1 = sf + ttc1 + lsc1 + osc + gtc;
st2 = sf + ttc2 + lsc2 + osc + gtc;
gst1 = st1 * 0.07;
gst2 = st2 * 0.07;
if(ttt[pos] <= 100 || tls[pos] <= 100)
{
tb1 = st1 + gst1;
printf("Total Bill is:%.2f\n", tb1);
}
else
{
tb2 = st2 + gst2;
printf("Total Bill is:%.2f\n", tb2);
}

printf("\n\n");
}

if(sp[pos] == 'B' || sp[pos] == 'b');
{
sf = 38;

if(ttt[pos] <= 200)
{
ttc1 = ttt[pos] * 0.15;
printf("Talk time cost is:%.2f\n", ttc1);
}
else
{
ctt = ttt[pos] - 200;
ttc2 = ctt *0.15;
printf("Talk time cost is:%.2f\n", ttc2);
}

if(tls[pos] <= 100)
{
lsc1 = tls[pos] * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc1);
}
else
{
cls = tls[pos] - 100;
lsc2 = cls * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc2);
}

osc = tos[pos] * 0.15;
gtc = gprs[pos] * 0.50;

printf("Overseas SMS Cost is:%.2f\n", osc);
printf("GPRS Traffic Cost is:%.2f\n", gtc);

st1 = sf + ttc1 + lsc1 + osc + gtc;
st2 = sf + ttc2 + lsc2 + osc + gtc;
gst1 = st1 * 0.07;
gst2 = st2 * 0.07;
if(ttt[pos] <= 200 || tls[pos] <= 100)
{
tb1 = st1 + gst1;
printf("Total Bill is:%.2f\n", tb1);
}
else
{
tb2 = st2 + gst2;
printf("Total Bill is:%.2f\n", tb2);
}
printf("\n\n");
}

if(sp[pos] == 'C' || sp[pos] == 'c');
{
sf = 65;

if(ttt[pos] <= 500)
{
ttc1 = ttt[pos] * 0.13;
printf("Talk time cost is:%.2f\n", ttc1);
}
else
{
ctt = ttt[pos] - 500;
ttc2 = ctt *0.13;
printf("Talk time cost is:%.2f\n", ttc2);
}

if(tls[pos] <= 300)
{
lsc1 = tls[pos] * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc1);
}
else
{
cls = tls[pos] - 300;
lsc2 = cls * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc2);
}

osc = tos[pos] * 0.15;
gtc = gprs[pos] * 0.50;

printf("Overseas SMS Cost is:%.2f\n", osc);
printf("GPRS Traffic Cost is:%.2f\n", gtc);

st1 = sf + ttc1 + lsc1 + osc + gtc;
st2 = sf + ttc2 + lsc2 + osc + gtc;
gst1 = st1 * 0.07;
gst2 = st2 * 0.07;
if(ttt[pos] <= 500 || tls[pos] <= 300)
{
tb1 = st1 + gst1;
printf("Total Bill is:%.2f\n", tb1);
}
else
{
tb2 = st2 + gst2;
printf("Total Bill is:%.2f\n", tb2);
}
printf("\n\n");
}

if(sp[pos] == 'D' || sp[pos] == 'd');
{
sf = 88;

if(ttt[pos] <= 700)
{
ttc1 = ttt[pos] * 0.13;
printf("Talk time cost is:%.2f\n", ttc1);
}
else
{
ctt = ttt[pos] - 700;
ttc2 = ctt *0.13;
printf("Talk time cost is:%.2f\n", ttc2);
}

if(tls[pos] <= 500)
{
lsc1 = tls[pos] * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc1);
}
else
{
cls = tls[pos] - 500;
lsc2 = cls * 0.05;
printf("Local SMS Cost is:%.2f\n", lsc2);
}

osc = tos[pos] * 0.15;
gtc = gprs[pos] * 0.50;

printf("Overseas SMS Cost is:%.2f\n", osc);
printf("GPRS Traffic Cost is:%.2f\n", gtc);

st1 = sf + ttc1 + lsc1 + osc + gtc;
st2 = sf + ttc2 + lsc2 + osc + gtc;
gst1 = st1 * 0.07;
gst2 = st2 * 0.07;
if(ttt[pos] <= 700 || tls[pos] <= 500)
{
tb1 = st1 + gst1;
printf("Total Bill is:%.2f\n", tb1);
}
else
{
tb2 = st2 + gst2;
printf("Total Bill is:%.2f\n", tb2);
}
}
break;
}
}


}


this is what i have done on case 2. it can be debug but all the 4 plan prices came out.
Last edited on
Help is easier to give, if we can see the code that you are referring to. And, please put the code between code tags. ( Located to the right, under Format: <> )
Just here:
1
2
3
4
// In the 'switch'...'case 2'
if(sp[pos] == 'A' || sp[pos] == 'a'); // <---- you put a semi-colon after the 'if'...the next code never will considered in the 'if'!

if(sp[pos] == 'A' || sp[pos] == 'a')  // <---- just delete the semicolon! 

Delete the semicolon for the 'if' of B,C,D too.
ty alot:) careless ^^
Topic archived. No new replies allowed.