I am instructed to do the following:
However, I'm not sure what the assignment means. Firstly, is "passed" supposed to be "past"?Add a user defined function which does the calculation involving the minor product code. It should be passed the minor part of the product_code and the base_price, and should return the (possibly) modified price.Add a second user defined function which does the calculation involving the major product code. It should be passed the major part of the product_code and the price calculated up to that point, and should return the (possibly) modified price.Add a third user defined function which does the calculation involving the shipping. It should be passed the "where" part of the product_code and the price calculated up to that point, and should return the final price.
Also, what does it mean to "return a possibly modified price"? Can anyone give me an example of how to use functions?
Here is my original code (which by the way, isn't even running due to the problem i mention here
Code:#include <stdio.h> int main() { int prod_num, number, counter=0, major_code=0, minor_code=0, tax_code=0, where=0, total_number=0; double base_cost, minor_factor=0, shipping_costs=0, tax_amount=0, final_unitprice=0,average_final, final_subtotal=0, final_price_product; while ( scanf("%d %lf %d", &prod_num, &base_cost, &number) != EOF) { total_number += number; counter++; major_code = prod_num / 100000; minor_code = (prod_num % 100000) / 100; tax_code = (prod_num % 100) / 10; where = prod_num % 10; if(minor_code >= 0 && minor_code <= 399) { minor_factor = 1.45; } else if ((minor_code>=400 && minor_code <=799) || (minor_code>=950 && minor_code <=955)) { minor_factor = 1.12; } else { minor_factor = 0.89; } switch(where) { case 0: shipping_costs = 7.50; break; case 1: shipping_costs = 8.47; break; case 2: shipping_costs = 6.05; break; case 3: shipping_costs = 10.20; break; default: shipping_costs = 20.00; break; } if(tax_code == 1) { if(major_code>=0 && major_code<=250) tax_amount = 0.12; else if(major_code>=251 && major_code<=450) tax_amount = 0.15; else tax_amount = 0.25; } else if (tax_code == 0) tax_amount = 0; final_unitprice = (base_cost * minor_factor + shipping_costs) * (1 + tax_amount); final_price_product = final_unitprice * number; final_subtotal += final_price_product; printf("---------------------------> PRODUCT [%d]<---------------------------\n", counter); printf("\n"); printf("Product #: %d || Price/Unit: $%.2f || # of Products: %d || Total: $%.2f\n", prod_num, final_unitprice, number, final_price_product); printf("\n"); printf("\n"); } average_final = final_subtotal / total_number; printf("\n"); printf("The total price is: $%.2f\n", final_subtotal); printf("The average price per product is: $%.2f", average_final); printf("\n"); return 0; }



LinkBack URL
About LinkBacks


