I have got the calculations all done. This is for my assignment. It is mandatory to include a for loop in this program. I can also include a do...while loop but the do...while is an optional one. I want to make sure this program can calculate as many bills as it can. For example, I want to pay for other people so the program will ask, "How many bills do you want to pay?" and I will key in the amount (eg: 2) & the program will run twice before terminating. The lines that I commented are my failed attempts btw. That is the only problem I have now. Thank you.
What I have tried:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a, count, num, planType, postpaid, prepaid, minCall, msgSent;
float billRate, callRate = 0.06 , smsRate = 0.01, totalBill ;
char custName[100], phoneNum[20];
printf("Enter your name: ");
gets(custName);
printf("\nEnter your phone number: ");
scanf(" %s", &phoneNum);
printf("\nWhich phone plan do you want to choose? (1 - postpaid, 2 - prepaid) ");
scanf(" %d", &planType);
if (planType == 1) {
printf("\nWhich postpaid plan do you want? (98, 128, 158, 188) ");
scanf(" %d", &postpaid);
}
if (postpaid == 98) {
printf("\nSubscribed to MaxisONE Plan 98!\nPlan includes 15GB All Day Data, 15GB Weekend Data and unlimited calls & SMS");
billRate = 98.00;
}
else if (postpaid == 128) {
printf("\nSubscribed to MaxisONE Plan 128!\nPlan includes 40GB All Day Data and unlimited calls & SMS");
billRate = 128.00;
}
else if (postpaid == 158) {
printf("\nSubscribed to MaxisONE Plan 158!\nPlan includes 50GB All Day Data and unlimited calls & SMS");
billRate = 158.00;
}
else if (postpaid == 188) {
printf("\nSubscribed to MaxisONE Plan 188!\nPlan includes 60 GB All Day Data and unlimited calls & SMS");
billRate = 188.00;
}
else {
printf("\nWhich prepaid plan do you want? (35, 45, 60, 70) ");
scanf(" %d", &prepaid);
switch(prepaid) {
case 35 :
printf("\nSubscribed to Hotlink RED Plan 35!\n30-day validity Plan which includes 6GB All Day Data, free Non-Stop RED Chat or free Non-Stop RED Social");
billRate = 35.00;
break;
case 45 :
printf("\nSubscribed to Hotlink RED Plan 45!\n30-day validity Plan which includes 8GB All Day Data, free Non-Stop RED Chat or free Non-Stop RED Social");
billRate = 45.00;
break;
case 60 :
printf("\nSubscribed to Hotlink RED Plan 60!\n30-day validity Plan which includes 6GB All Day Data, unlimited calls & SMS, free Non-Stop RED Chat or free Non-Stop RED Social");
billRate = 60.00;
break;
case 70 :
printf("\nSubscribed to Hotlink RED Plan 70!\n30-day validity Plan which includes 8GB All Day Data, unlimited calls & SMS, free Non-Stop RED Chat or free Non-Stop RED Social");
billRate = 70.00;
}
}
printf("\n ");
printf("\n===================================================\n");
printf("\t\tMAXIS eBILL");
printf("\n===================================================\n");
time_t t = time(NULL);
struct tm *tm = localtime(&t);
printf("Date & Time: %s\n", asctime(tm));
printf("Name: ");
puts(custName);
printf("Phone Number: %s", phoneNum);
printf("\nPlan Type: %d", planType);
if (planType == 1) {
printf("\nPostpaid Plan: %d", postpaid);
printf("\nTotal Bill: RM %.2f", billRate);
printf("\n====================================================\n");
}
else {
printf("\nPrepaid Plan: %d", prepaid);
printf("\nHow many messages sent this month? ");
scanf(" %d", &msgSent);
printf("How long are your calls this month? (minutes) ");
scanf(" %d", &minCall);
totalBill = (callRate*2*minCall) + (smsRate*msgSent) + billRate;
printf("Total Bill: RM %.2f", totalBill);
printf("\n===================================================\n");
}
}