Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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) {

   /* for loop execution */
        //for( a = 1; a <= 1; a = a + 1 ){
        //printf("\nHow many bills do you want to pay? ");
        //scanf(" %d", &a);
        //}
        
    /*for loop trial*
        int num, count, sum = 0;

    printf("Enter how many bills you want to pay: ");
    scanf("%d", &num);

    // for loop terminates when n is less than count
    for(count = 1; count <= num; ++count)
    {
        sum += count;
    }*/

        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");

    }
}
Posted
Updated 25-Mar-18 6:23am
Comments
nv3 25-Mar-18 11:14am    
Sorry, we don't do homework here.

1 solution

It would help to define a struct for a costumer and an array for all costumers
C++
struct {
char name[100];
char phoneNum[20];
double bill
} _CUSTOMER;
_CUSTOMER costumer[20];// memory for 20 customers
Search some tutorial to Learn C++
You must decide how to terminate the for loops.
C++
printf("How many costumers?");
scanf("%d", &num);

 // for loop terminates when n is less than count
 for(i= 1; i<= num; ++i)
 {
   // here goes all codeof one costumers like
   printf("Enter name %d: ",i);
   scanf("%s", costumer[i].name);//scan first name
 }
 
Share this answer
 
v2
Comments
Richard Deeming 27-Mar-18 10:24am    
costumer - A person who designs, makes or supplies theatrical costumes.

customer - A patron; one who purchases or receives a product or service from a business or merchant, or intends to do so.

Seems to be a common typo recently. :)
Richard Deeming 27-Mar-18 10:24am    
Also, your link is broken.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900