Hello AkiraC,
Going over your code I still have no idea what "QsA" and "SaA" are for. I am thinking that they are for a total quantity and total sales?
This is not completely fixed, but a start:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#define PACKAGE_A 24.50f
#define DELIVERY_FEES 5.00f
void main()
{
int qtyA = 0, QsA = 0, totalQty = 0; // <--- ALWAYS initialize all your variables.
float
pA = 0.0,
SaA = 0.0,
PACKAGECharges = 0.0,
TotaltoPay = 0.0,
delivery = 0.0,
discounts = 0.0,
totalPackageCharge = 0.0;
char yesno = '\0';
for (qtyA = 0; qtyA <= 0; ++qtyA)
{
QsA = QsA + qtyA;
SaA = QsA * PACKAGE_A;
do
{
printf(
"\n Enter order quantity of package \n"
" Package A RM24.50 : ");
scanf(" %d", &qtyA); // <--- Return value ignored.
pA = qtyA * PACKAGE_A;
PACKAGECharges = pA;
totalQty += qtyA;
totalPackageCharge += pA;
if (PACKAGECharges < 80)
{
delivery = DELIVERY_FEES;
discounts = 0.00;
TotaltoPay = PACKAGECharges + delivery;
}
else
{
delivery = 0.00;
discounts = PACKAGECharges * 0.15f;
TotaltoPay = PACKAGECharges + delivery - discounts;
}
printf(
"\n CUSTOMER ORDERS \n"
" PACKAGE A %d @ 24.50 = RM %6.2f \n"
"\n"
" PACKAGE Charges = RM %6.2f \n"
" Delivery Fees = RM %6.2f \n"
" Discounts = RM %6.2f \n"
" Total to Pay = RM %6.2f \n", qtyA, pA, PACKAGECharges, delivery, discounts, TotaltoPay);
//printf("\n");
printf("\n Next customer (Y=yes?) : ");
scanf(" %c", &yesno); // <--- Return value ignored.
} while (yesno == 'Y' || yesno == 'y');
if (yesno = 'N' || yesno == 'n')
{
QsA = QsA + qtyA;
SaA = QsA * PACKAGE_A;
printf(
"\n DAILY SALES SUMMARY REPORT \n"
"PACKAGE\t\tQuantity Sold\tSales Amount\n"
" A\t\t%d\t\t%-0.2f\n", totalQty, totalPackageCharge);
}
}
printf("\n\n"); // <--- Added.
system("pause");
}
|
For lines 7 and 8 you are making 2 constant variables. These tend to work better using capital letters. Also "24.50" is considered a "double" with my IDE, but it is more set up for C++ not C. If your compiler is for C programs adding the "f" after the number may not be required. For me it just eliminated some warnings going from a "double to a "float".
It may just be a language difference, but I added the variables "totalQty" and "totalPackageCharge", so I could understand it better.
The for loop only loops 1 time and since all the work is done in the do/while loop there is not much point in it.
As
seeplus noted lines 25 and 26 are in the wrong place to be of any use.
You do not need a "printf" statement for every line. Most lines should be able to be combined, as I have demonstrated.
In my IDE MSVS 2019 each string in double quotes is considered as just 1 big string.
Lines 71 and 72 I did not do anything with because mostly I did not use those variables. As
seeplus noted I do not believe they do any good there.
The code is an idea of what could be done. Feel free to change it to use your original variables if you want.
The output I get:
Enter order quantity of package
Package A RM24.50 : 1
CUSTOMER ORDERS
PACKAGE A 1 @ 24.50 = RM 24.50
PACKAGE Charges = RM 24.50
Delivery Fees = RM 5.00
Discounts = RM 0.00
Total to Pay = RM 29.50
Next customer (Y=yes?) : y
Enter order quantity of package
Package A RM24.50 : 2
CUSTOMER ORDERS
PACKAGE A 2 @ 24.50 = RM 49.00
PACKAGE Charges = RM 49.00
Delivery Fees = RM 5.00
Discounts = RM 0.00
Total to Pay = RM 54.00
Next customer (Y=yes?) : y
Enter order quantity of package
Package A RM24.50 : 3
CUSTOMER ORDERS
PACKAGE A 3 @ 24.50 = RM 73.50
PACKAGE Charges = RM 73.50
Delivery Fees = RM 5.00
Discounts = RM 0.00
Total to Pay = RM 78.50
Next customer (Y=yes?) : n
DAILY SALES SUMMARY REPORT
PACKAGE Quantity Sold Sales Amount
A 6 147.00
Press any key to continue . . .
|
Andy