Yes I'm doing a self study correspondence for computer science through texas tech and i need some help with a project im working on. It involves "setprecision" manipulators..
OK so here's my problem.. I'm working on a pragram that asks the user for two floating point numbers.(i got that down.) now it multiplies them and prints them to to the screen. Well i got all that but next im supposed to prompt the user for "how many digits to displayt tot the right of the decimal". Well i've been through my book and i can't find a solution. The best i'v have is using the setprecision, but i dont' know how to prompt the user to set the precision. any help would be nice....
======================
here's the code
======================
/*
Name: Project6_3.cpp
Author: William Smith
Date: 01/11/04
Description: A program that asks the user for two floating-point
numbers. The program should mulitply the numbers
together and print the product to the screen.
Next it asks the user how many digits to display to
the right of the decimal point and print the product
again with the new precision.
*/
#include <iostream.h>
#include <iomanip.h>
main()
{
float a,b,c,p;
cout << "Enter two numbers: \n";
cin >> a >> b;
c = a * b;
cout << "The product is: " << c << "\n";
cout << " \n";
cout << "Now enter the number of units to
display: ";
cin >> p;
//now here's where im stuck...!
cout << "\n";
system("pause");
return 0;
}
OK so here's my problem.. I'm working on a pragram that asks the user for two floating point numbers.(i got that down.) now it multiplies them and prints them to to the screen. Well i got all that but next im supposed to prompt the user for "how many digits to displayt tot the right of the decimal". Well i've been through my book and i can't find a solution. The best i'v have is using the setprecision, but i dont' know how to prompt the user to set the precision. any help would be nice....
======================
here's the code
======================
/*
Name: Project6_3.cpp
Author: William Smith
Date: 01/11/04
Description: A program that asks the user for two floating-point
numbers. The program should mulitply the numbers
together and print the product to the screen.
Next it asks the user how many digits to display to
the right of the decimal point and print the product
again with the new precision.
*/
#include <iostream.h>
#include <iomanip.h>
main()
{
float a,b,c,p;
cout << "Enter two numbers: \n";
cin >> a >> b;
c = a * b;
cout << "The product is: " << c << "\n";
cout << " \n";
cout << "Now enter the number of units to
display: ";
cin >> p;
//now here's where im stuck...!
cout << "\n";
system("pause");
return 0;
}