c++ - Calculation not returning correct value -
asked write program: "a software company sells package retails $99. quantity discounts given according following table:
quantity discount 10-19 20% 20-49 30% 50-99 40% 100 or more 50% write program asks number of units sold , computes total cost of purchase. input validation: make sure number of units greater 0"
this have far:
#include <iostream> #include <string> //string class- string of text #include <iomanip> //required setw= field width of value after using namespace std; int main() { double sales, charges, numofunits = 0, ratea = .20, rateb = .30, ratec = .40, rated = .50; //set numeric output formatting: cout << fixed << showpoint << setprecision(2); cout << "enter quantity order: "; cin >> sales; // determine discount: double price=99.0; if (sales >= numofunits) if (sales >= 10 && sales <= 19 ) ratea; charges = price - ratea *sales; if (sales >= 20 && sales <= 49) rateb; charges = price - rateb *sales; if (sales >= 50 && sales <= 99) ratec; charges = price - ratec *sales; if (sales > 100 ) rated; charges = price - rated *sales; cout << "your total price quantity is: $" <<charges << " per unit."<< endl; cout << "that invalid number. run program again\n " << "and enter number greater than\n" << numofunits << ".\n"; } after compiling, output not give me right answers. maybe math wrong, or flow off? suggestions?
i not want write me, maybe give me pointers
you need use braces {} around multi-line conditions
if (sales >= 10 && sales <= 19 ) ratea; charges = price - ratea *sales; is actually
if (sales >= 10 && sales <= 19 ) ratea; charges = price - ratea *sales; i.e. ratea executed conditionally , update charges executed.
also, statements ratea; have no effect should either updated or removed.
Comments
Post a Comment