Ask your own question, for FREE!
Computer Science 27 Online
OpenStudy (adunb8):

what is setw( ) and setprecision () and how do i use them?

OpenStudy (walters):

setw() under iomanip use to make space by simply writing the value inside the parentheses setpreecision=it set a number of digits after a comma (it is also under iomanip)

OpenStudy (adunb8):

here is my code : #include <iostream> #include <string> #include <iomanip> using namespace std; int main() { float a= 3.0, b= 5.0, c = 7.1, d=8.3, e=2.2, f=3.2 , g= 6.1, product ; int h=5 ; cout << " " << setprecision(2) << a << endl; cout << "*" << setprecision(2) << b << endl; cout << "----------" << endl; product = a*b ; cout << product << endl; system ("pause") ; }

OpenStudy (adunb8):

however the setprecision is not working

OpenStudy (walters):

#include <iostream> #include <string> #include<iomanip> using namespace std; int main() { float product ;//your type must b type float float a= 3.0, b= 5.0, c = 7.1, d=8.3, e=2.2, f=3.2 , g= 6.1; int h=5 ;//wat is the use of c,d,e,f,g,h cout << " " << a <<endl; cout<< "* "<<b<<endl; cout << "-------------" << endl; cout<<setprecision(2) <<fixed; product = 3.0*5.0 ; cout << product << endl; system ("pause") ; }

OpenStudy (walters):

hey gotta sleep bye-bye

OpenStudy (adunb8):

tnx!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!