#include <stdio.h>
struct invoice {
char partNumber[25];
char partDescription[25];
int itemQuantity;
float itemPrice;
};
float invoice_amount(int quantity, float price) {
if (quantity < 0) { quantity = 0; }
return quantity * price;
}
int main() {
struct invoice Invoice1 = {"ed34", "Screw Guage", 2, 30};
struct invoice Invoice2 = {"e322", "Screws", 10, 3};
printf("Invoice1's initial part number is: %s,"
"\npart description is: %s, "
"\nquantity per item is: %d, "
"\nprice per item is: %f, "
"\ninvoice amount: %f ",
Invoice1.partNumber,
Invoice1.partDescription,
Invoice1.itemQuantity,
Invoice1.itemPrice,
invoice_amount(Invoice1.itemQuantity, Invoice1.itemPrice));
printf("\n\nInvoice2's initial part number is: %s,"
"\npart description is: %s, "
"\nquantity per item is: %d, "
"\nprice per item is: %f, "
"\ninvoice amount: %f ",
Invoice2.partNumber,
Invoice2.partDescription,
Invoice2.itemQuantity,
Invoice2.itemPrice,
invoice_amount(Invoice2.itemQuantity, Invoice2.itemPrice));
return 0;
}
Comments
Convert this code in C language.
Leave a comment