// Program to test "totalprice" function. #include #include // has EXIT_SUCCESS, EXIT_FAILURE #include // has setiosflags, setprecision // Pre: N, price, taxrate all >= 0. // Post: return value is price-with-tax for N items costing "price" // each, plus sales tax at taxrate/100. double totalprice(int N, double price, double taxrate) { return N * price * (1 + taxrate/100); } int main(void) { int N; double price, taxrate; cout << "Enter number of items, price, tax rate:\n"; cin >> N >> price >> taxrate; if (N < 0 || price < 0 || taxrate < 0) { cout << "Error! bad input.\n"; exit(EXIT_FAILURE); } // set up to print with exactly 2 decimal places. cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(2); cout << "number of items = " << N << endl; cout << "price per item = $" << price << endl; cout << "tax rate = " << taxrate << endl; cout << "total price = $" << totalprice(N, price, taxrate) << endl; return EXIT_SUCCESS; }