Click here to Skip to main content
15,065,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#pragma warning(disable:4996)

int main(void)
{
    //Package category array
    char category[] = { 'A', 'B', 'C', 'D' };
    //Price array
    float price[] = { 24.50, 26.00, 27.50, 29.00 };
    //Quantiy array
    int quantity[] = { 0, 0, 0, 0 };
    int count = 1;
    int qtyA = 0, qtyB = 0, qtyC = 0, qtyD = 0,n[20];
    float total = 0.0, discount = 0.0, delivery = 0.0, net = 0.0;
    char ch = 'A', choice = 'Y';

    printf("\n<MENU PRICES OF VEGETABLE>");
    printf("\n===============================================================================");
    printf("\n MR.KOK VEGETABLE ORDERING SYSTEM");
    printf("\n===============================================================================");

    //Continue taking customer input till choice is not 'N' or 'n'
    while (choice != 'n' && choice != 'N') {
        printf("\nCustomer no. : %d", count++);
        //Continue taking the package and quantity input till X
        while (ch != 'X') {
            printf("\n\nPACKAGE A,B,C,D (X = EXIT) : ");
            scanf("%c", &ch);
            getchar();
            //Increment respective quantity of each category
            if (ch == 'A') {
                printf("\nQuantity : ");
                scanf("%d", &qtyA);
                getchar();
                quantity[0] += qtyA;
            }
            if (ch == 'B') {
                printf("\nQuantity : ");
                scanf("%d", &qtyB);
                getchar();
                quantity[1] += qtyB;
            }
            if (ch == 'C') {
                printf("\nQuantity : ");
                scanf("%d", &qtyC);
                getchar();
                quantity[2] += qtyC;
            }
            if (ch == 'D') {
                printf("\nQuantity : ");
                scanf("%d", &qtyD);
                getchar();
                quantity[3] += qtyD;
            }
        }

        //Print the details of package and add to total
        printf("\n=======================================================================");
        if (qtyA != 0) {
            printf("\nPACKAGE A : %d @ RM 24.50 = RM %.2f", qtyA, qtyA * price[0]);
            total += qtyA * price[0];
        }
        if (qtyB != 0) {
            printf("\nPACKAGE B : %d @ RM 26.00 = RM %.2f", qtyB, qtyB * price[1]);
            total += qtyB * price[1];
        }
        if (qtyC != 0) {
            printf("\nPACKAGE C : %d @ RM 27.50 = RM %.2f", qtyC, qtyC * price[2]);
            total += qtyC * price[2];
        }
        if (qtyD != 0) {
            printf("\nPACKAGE D : %d @ RM 29.00 = RM %.2f", qtyD, qtyD * price[3]);
            total += qtyD * price[3];
        }
        printf("\n=======================================================================\n");

        //Check the total value of purchase and update the delivery and discount
        if (total > 80) {
            printf("\nPACKAGE CHARGES : RM %.2f", total);
            if (total > 100) {
                delivery = 0.0;
                printf("\nDelivery fees : RM%.2f", delivery);
                discount = 0.15 * total;
                printf("\nDiscount : RM%.2f", discount);
            }
            //Calculate the net amount to be paid by Customer
            net = total + delivery - discount;
        }

        else {
            printf("\nPACKAGE CHARGES : RM %f", total);
            delivery = 5.0;
            printf("\nDelivery fees : RM%.2f", delivery);
            discount = 0.0 * total;
            printf("\nDiscount : RM%.2f", discount);
            net = total + delivery - discount;
        }

        //print the total amount
        printf("\nTotal to pay : RM %.2f", net);
        ch = 'A'; qtyA = 0; qtyB = 0; qtyC = 0;
        printf("\n\nTHANK YOU, HAVE A NICE DAY!");
        qtyD = 0; total = 0.0;
        //Ask if next Customer is available
        printf("\n\nNext Customer ? (Y/N) : ");
        scanf("%c", &choice);
        getchar();
    }

    //Print the daily sales report
    printf("\n=======================================================================");
    printf("\n\n>>>>>>>>>>>>>>>>>>>>>>>>DAILY SALES REPORT<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
    printf("\n=======================================================================");
    printf("\nPACKAGE\tQUANTITY SOLD\tSALES AMOUNT\n");
    printf("\n=======================================================================\n");
    int i = 0;
    while (i < 4) {
        printf("%c\t%d\t\t%.2f\n", category[i], quantity[i], quantity[i] * price[i]);
        i++;
    }
    printf("\n=======================================================================");


    return 0;
}


What I have tried:

i want to input the personal information before the "while"

Please help and teach me .. thanks
Posted
Updated 29-Aug-21 8:00am

Use scanf and printf just as you have been doing. If you don't know how to use them then read the documentation. In other words, teach yourself. It's not that hard.

Documentation links :
scanf - C++ Reference[^]
printf - C++ Reference[^]

Given the code you already have (which you wrote, right?) these are small additions.
   
Than write some extra code for it, The scanf has also parameters for input of strings.

tips:
- check that the buffer for the strings is big enough
- use structs and functions to seperate code and features
- use the debugger
   

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