-4

newbie learning C++ and not understanding the problem I have trying to use setprecision(2) says setprecision(2) is undefined. If anyone could help I'd be most grateful.

 #include <iostream>     
 #include <string>
using namespace std;

int main() 
{
double price,shipping;

cout<<"Enter total price of of the order: "<<endl;
cin>>price;

if(price > 75) 
    shipping = 0;
else if(price > 50) 
    shipping = 5;
else if(price > 25)
    shipping = 10;
else if(price > 0)
    shipping = 15;

cout<<"Total price of order including shipping is: "<<fixed<<setprecision(2)
    <<price + shipping<<endl;





return 0;
system("pause");
}
Sam777
  • 19
  • 1
  • 2
  • 7
  • Learn to love the documentation. Open documentation for `std::setprecision` and read it. Also, stop `using namespace std;`. – SergeyA Jun 14 '16 at 20:42
  • ok thanks, stupidly enough as soon as I posted this I found the solution doh – Sam777 Jun 14 '16 at 20:43
  • 1
    Add `#include ` to your includes – WhiZTiM Jun 14 '16 at 20:44
  • I have to use using namespace std; as I am using virtual studio. – Sam777 Jun 14 '16 at 20:47
  • 1
    He's suggesting you prefix your std namespace tokens with std:: rather than using "using namespace std." For example, std::cout, std::cin, etc. You can remove the "using namespace std" if you do that. See: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-in-c-considered-bad-practice – Evan Jun 14 '16 at 20:57

1 Answers1

3

setprecision() function is included in the iomanip library. Simply include that library into your program. and you should be fine. :)

#include<iomanip>
Aconcagua
  • 24,880
  • 4
  • 34
  • 59