Thread: Need help rounding to the hundreth decimal place

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    Need help rounding to the hundreth decimal place

    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
    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&#37;";
    	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;
    }
    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?
    Last edited by bardler; 02-27-2008 at 01:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary traslator
    By NiVaG in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2005, 07:01 PM
  2. deciaml place help
    By artgirloc in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2002, 07:47 PM
  3. Replies: 10
    Last Post: 06-12-2002, 03:15 PM
  4. rounding program...s.o.s.
    By pancho in forum C Programming
    Replies: 3
    Last Post: 02-11-2002, 10:22 PM
  5. Berlin: Searching for a place to stay
    By fabs in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-14-2002, 02:18 AM