Jul 5, 2013 at 6:16pm UTC
#include<stdio.h>
#include<stdlib.h>
#define prepaid_bal 10
double new_balance = prepaid_bal;
double call_time, call_1, total_1;
double call_2, total_2;
double call_3, total_3;
double sum_of_call;
double sms_send, charge_sms_send;
double top_up;
void call(), sms(), topup(), exit();
int menu();
void main()
{
new_balance = prepaid_bal;
system("pause");
menu();
}
int menu()
{
int code;
printf("1.call\n 2.sms\n 3.topup\n 4.exit\n");
printf("Dear customer,which service you wan?\nPlease choose the service you wan by entering the code:");
scanf("%d", &code);
switch (code)
{
case 1:
call();
break;
case 2:
sms();
break;
case 3:
topup();
break;
case 4:
exit();
break;
default:
menu();
break;
}
}
//call
void call()
{
double const band1 = 0.50;
double const band2 = 0.40;
double const band3 = 0.20;
call_1 = 0;
total_1 = 0;
call_2 = 0;
total_2 = 0;
call_3 = 0;
total_3 =0;
printf("call duration(minutes): ");
scanf("%lf", &call_time);
if(call_time>0 && call_time<= 10)
{
call_1 = call_time;
total_1 = band1 * call_1;
}
else if(call_time >10 && call_time <=20)
{
call_1 = 10;
total_1 = 5;
call_2 = call_time;
call_2 -= 10;
total_2 = band2 * call_2;
}
else if(call_time >20)
{
call_1 = 10;
total_1 = 5;
call_2 = 10;
total_2 = 4;
call_3 = call_time;
call_3 -=20;
total_3 = band3 *call_3;
}
sum_of_call = total_1 + total_2 + total_3;
printf("\nBand 1 :%.2f minutes @ %.2f = RM %.2f ", call_1, band1, total_1);
printf("\nBand 2 :%.2f minutes @ %.2f = RM %.2f ", call_2, band2, total_2);
printf("\nBand 3 :%.2f minutes @ %.2f = RM %.2f ", call_3, band3, total_3);
printf("\n -----------");
printf("\n Charge for this call = RM %.2f ", sum_of_call);
printf("\n -----------");
new_balance -= sum_of_call;
printf("\n\nYour new Balance = RM%.2f\n", new_balance);
}
//sms
void sms()
{
double const sms_charge = 0.10;
printf("\nHow many sms do you want to send? ");
scanf("%lf", &sms_send);
charge_sms_send = sms_send * sms_charge;
printf("SMS charge =RM%.2lf", charge_sms_send);
new_balance -= charge_sms_send;
printf("\n\nYour new balance is :RM%.2lf", new_balance);
}
//topup
void topup()
{
printf("Amount to Top Up? RM");
scanf("%lf", &top_up);
new_balance += top_up;
printf("\nYour new balance =RM%.2lf", new_balance);
}
//summary
void exit()
{
printf("\n\n TRANSACTION SUMMARY");
printf("\nStarting Balance : RM%d", prepaid_bal);
printf("\nTotal Amount Topped Up : RM%.2lf", top_up);
printf("\nTotal Call charges : RM%.2lf", sum_of_call);
printf("\nTotal SMS charges : RM%.2lf", charge_sms_send);
printf("\nEnding Balance : RM%.2lf", new_balance);
}