scientific notation problem
Feb 24, 2014 at 8:03pm UTC
Write your question here.
hey guys I have slight problem in my scientific notation output my exponent is displaying 3digits and I want it to display 2 digits 4 example instead of outputting 3.00e+006 I want it to output 3.00e+06.....any help wud be appriciated
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include <iostream>
#include<vector>
#include<fstream>
#include<iomanip>
using namespace std;
void getValuesFromFile(vector<float >&R1,vector<float >&R2,vector<float >&R3)
{
float r1=0;
float r2=0;
float r3=0;
ifstream infile("indata.txt" );
while (infile>>r1>>r2>>r3)
{
R1.push_back(r1);
R2.push_back(r2);
R3.push_back(r3);
}
}
void calculate(vector<float >R1,vector<float >R2,vector<float >R3)
{
float Ra=0.0;
float Rb=0.0;
float Rc=0.0;
float Rd=0.0;
for (int i=0;i<R1.size();i++)
{
Ra=R1[i]+R2[i]+R3[i];
Rb=(R1[i]*R2[i]*R3[i])/(R1[i]*R2[i]+R2[i]*R3[i]+R3[i]*R1[i]);
Rc=R1[i]+(R2[i]*R3[i])/(R2[i]+R3[i]);
Rd=((R1[i]+R2[i])*R3[i])/(R1[i]+R2[i]+R3[i]);
cout<<setprecision(2)<<scientific<<Rb<<" " <<Rd<<" " <<Rc<<" " <<Ra<<endl;
}
}
int main()
{
vector<float > R1;
vector<float >R2;
vector<float > R3;
getValuesFromFile(R1,R2,R3);
calculate(R1,R2,R3);
return 0;
}
Feb 24, 2014 at 8:10pm UTC
Try putting this line in line 41 of your code, just before the cout statement:
Feb 24, 2014 at 8:21pm UTC
Try using the printf function....
1 2 3 4
...
float x = 4.5695;
printf("%.2lf\n" , x);
...
Topic archived. No new replies allowed.