可能性の重複:このコードでは
Equation not working correctly in C++
Help with POW function in C++Cは、varが丸めフロート++
:
//Samuel LaManna
//Program 1 (intrest rate)
/*Variables:
Principal=P
Interest Rate=R
Times Compounded=T
Savings=S
Interest=I */
#include <iostream> //Input/output
#include <cmath> //Math Functions
using namespace std;
int main()
{
float P, R, T, S, I; //Declaring Variables
cout<<endl;
cout<<"Interest Earned Calculator"; //Prints program title
cout<<endl;
cout<<endl;
cout<<"Please enter the Principal Value: ";
cin >> P;
cout<<endl;
cout<<endl;
cout<<"Please enter the Interest Rate (in decimal form): ";
cin >> R;
cout<<endl;
cout<<endl;
cout<<"Please enter the Number of times the interest is compounded in a year: ";
cin >> T;
cout<<endl;
cout<<endl;
S=pow(1+R/T,T)*P; //Equation to find Savings
I=S-P; //Equation to find interest in $
cout<<"Interest Rate: " << R*100 <<"%" ;
cout<<endl;
cout<<endl;
cout<<"Times Compounded: " << T;
cout<<endl;
cout<<endl;
cout<<"Principal: $" << P;
cout<<endl;
cout<<endl;
cout<<"Interest: $" << I;
cout<<endl;
cout<<endl;
cout<<"Ammount in Savings: $" << S;
cout<<endl;
cout<<endl;
return 0;
}
最終的な出力数ラウンドを作るための方法がありますたとえ0であっても小数点以下2桁まで?
[何を試しましたか?](http://mattgemmell.com/2008/12/08/what-have-you-tried) –
[setprecision](http://www.cplusplus。 –
私は知りませんでした、私は始めることができました、先生は先に働いています。 –