Need a little help with this program please. How come it doesn't return any values (other than 0) for cost, tax, and charges?
Here's the pseudocode that i coded from:
and the code I wrote:Code:input qty while qty > 0 input size call Calculate Scrap using 10 to get scrap 10, qty needed for 10 call Calculate Scrap using 25 to get scrap 25, qty needed for 25 call Calculate Scrap using 40 to get scrap 40, qty needed for 40 if scrap 10 < scrap 25 and < scrap 40 set qty needed to qty needed for 10 set price to 2.10 else if scrap 25 < scrap 10 and < scrap 40 set qty needed to qty needed for 25 set price to 4.90 else set qty needed to qty needed for 40 set price to 7.51 multiply qty needed by price to get cost multiply cost by 1.75 multiply cost by .08 to get tax add tax to cost to get charges output cost, tax, charges input qty Calculate Scrap divide stock by size to get per stock call floor using per stock if size *(per stock + 1/16) > stock subtract 1 from per stock divide qty by per stock to get qty needed call ceiling using qty needed multiply per stock by size to get shipped subtract shipped from stock to get scrap multiply scrap by qty needed
I think I may be passing the values wrong to the function or returning the improper value. Let me know what you think. Any help is appreciated.Code:#include<iostream> #include<math.h> using namespace std; int Calculate_Scrap(int qtyneeded, int size, int qty); int main() { int qty, size, qtyneeded; double price, cost, tax, charges; int scrap10, scrap25, scrap40; cout <<"\n Enter the quantity: " << endl; cin >> qty; while(qty > 0) { cout << "\n Enter the size: " << endl; cin >> size; scrap10 = Calculate_Scrap(qtyneeded = 10, size, qty); scrap25 = Calculate_Scrap(qtyneeded = 25, size, qty); scrap40 = Calculate_Scrap(qtyneeded = 40, size, qty); if(scrap10 < scrap25 < scrap40) { qtyneeded = scrap10; price = 2.10; } else if(scrap25 < scrap10 < scrap40) { qtyneeded = scrap25; price = 4.90; } else { qtyneeded = scrap40; price = 7.51; } cost = qtyneeded * price; cost = cost * 1.75; tax = cost * 0.08; charges = tax + cost; cout << "\n The cost is " << cost; cout << "\n The tax is " << tax; cout << "\n The charges are " << charges << endl; cout << "\n Enter the quantity or 0 to exit: " << endl; cin >> qty; } return 0; } int Calculate_Scrap(int qtyneeded, int size, int qty) { double perstock, stock, shipped, scrap; stock = 10000; perstock = stock / size; floor(perstock); if((size *(perstock + 1/16)) > stock) { --perstock; } qtyneeded = qty / perstock; ceil(qtyneeded); shipped = perstock * size; scrap = stock - shipped; return scrap * qtyneeded; }
Thanks!



LinkBack URL
About LinkBacks



CornedBee