i just started C++ programming and I need to write a program that caculates sales tax and the sales tax comes out to 2.375 and i need it to come out to 2.38.
my program is
instead of declaring the "salestaxof" variable as double is there a way to declare it so it rounds up to the nearest hundreth decimal place?Code:// ---------------------------------------------------------- #include <iostream> using namespace std; int main() { // (1) Declare program variables double wholesaleprice, storemarkupP, salestaxof, storemarkup, sellingprice, total; const double salestax = 8.25; // (2) Read in program inputs cout << "xxxxxxxxxxxxxxxxxxxx\nxEASY BUSINESS CALCx\nxxxxxxxxxxxxxxxxxxxx"; cout << "\nEnter the wholesale price, then press enter\n$"; cin >> wholesaleprice; cout << "Enter the markup percentage, then press enter\n%"; cin >> storemarkupP; // (3) Compute the program outputs storemarkup = storemarkupP * (.01 * wholesaleprice); sellingprice = wholesaleprice + storemarkup; salestaxof = sellingprice * (.01 * salestax); total = salestaxof + sellingprice; // (4) Display the results to file or screen cout << " Whole sale price: $" << wholesaleprice << endl; cout << "Store markup price: $" << storemarkup << endl; cout << " Selling price: $" << sellingprice << endl; cout << " Sales tax: $" << salestaxof << endl; cout << " Total: $" << total << endl; return 0; }



LinkBack URL
About LinkBacks





I would probably do it the way the OP has it myself.