Big-Bazaar wants an application for Billing.
Biller will enter the following details
Type of customer ( ‘R’ - Regular, ‘S’ - Special),
Product number,
Product cost per unit (greater than 10) and
Quantity purchased.(between 1 and 100)
Application should not accept any wrong entry other than as specified above.
Discount offered by shopping Mall
Gives 10% discount for Special customers.
If total billing amount is more than 1000, additional 5% discount is applied.
Application should apply all possible discount and Display Final Bill amount
All variables must have meaningful names(readable)
Variables should have proper data-types
#include <stdio.h>
struct customer {
char type;
int product_number;
int cost_per_unit;
int quantity;
};
int read_char(const char *msg,
char c[],
int n,
char *dest)
{
printf("%s: ", msg);
scanf("%c", dest);
int bool = 0;
for (int i = 0; i < n; i++) {
if (strcmp(c[i], dest) == 0) {
bool = 1;
}
}
return bool;
}
int read_int(const char *msg,
int min,
int max,
int *dest)
{
printf("%s: ", msg);
scanf("%d", dest);
return min <= *dest && *dest <= max;
}
int main() {
char type[2] = {'R', 'S'};
struct customer cm;
while (!read_char("Type", type, 2, &cm.type));
while (!read_int("Product number", 0, INT_MAX, &cm.product_number));
while (!read_int("Product cost per unit", 10, INT_MAX, &cm.cost_per_unit));
while (!read_int("Quantity", 1, 100, &cm.quantity));
if (cm.type == 'R') {
cm.cost_per_unit = cm.cost_per_unit - cm.cost_per_unit / 10;
}
printf("%d", cm.cost_per_unit * cm.quantity);
return 0;
}
Comments
Leave a comment