| | |
setprecision
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 9
Reputation:
Solved Threads: 0
I have #include<iomanip> header also and it's still not working.I am getting 2 dec places but it's .00 Why is that?Please help.
here is the code
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
also this code is not working ,when I use the [ ] at the end,I am getting an error so I am using () instead but the calculation is incorrect.Please help
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
#include <iostream>
#include<iomanip>
#include <cmath>
usingnamespace std;
int main()
{
char choice;
const int arraysize=20;
int num[arraysize];
do
{
cout<<"I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:"<<endl;
cin>>choice;
if(choice =='Y'||choice =='y')
{
cout<<"How many numbers will you enter? (up to 20)?"; cin>>num[arraysize];
for (int j=0;j<num[arraysize];j++)
{
cout<<"Enter Number"<<j+1<<":"; cin>> num[j];
}
cout << " You have entered the following:"<<endl;
for (j = 0; j < num[arraysize]; j++)
{
cout << num[j]<<" ";
}
int sum=0;
for (j=0;j<num[arraysize];j++)
sum+= num[j];
cout<<"\nThe Sum is "<<sum<<endl;
float mean= (sum/num[arraysize]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Varience is " <<var<<endl;
float sqrtvar=sqrt(var);
cout << showpoint << fixed << setprecision (2);
cout<<"The Standard deviation is "<<sqrtvar<<endl;
}
}while(choice!='N'&& choice!='n');
return 0;
}
here is the code
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
also this code is not working ,when I use the [ ] at the end,I am getting an error so I am using () instead but the calculation is incorrect.Please help
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
#include <iostream>
#include<iomanip>
#include <cmath>
usingnamespace std;
int main()
{
char choice;
const int arraysize=20;
int num[arraysize];
do
{
cout<<"I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:"<<endl;
cin>>choice;
if(choice =='Y'||choice =='y')
{
cout<<"How many numbers will you enter? (up to 20)?"; cin>>num[arraysize];
for (int j=0;j<num[arraysize];j++)
{
cout<<"Enter Number"<<j+1<<":"; cin>> num[j];
}
cout << " You have entered the following:"<<endl;
for (j = 0; j < num[arraysize]; j++)
{
cout << num[j]<<" ";
}
int sum=0;
for (j=0;j<num[arraysize];j++)
sum+= num[j];
cout<<"\nThe Sum is "<<sum<<endl;
float mean= (sum/num[arraysize]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Varience is " <<var<<endl;
float sqrtvar=sqrt(var);
cout << showpoint << fixed << setprecision (2);
cout<<"The Standard deviation is "<<sqrtvar<<endl;
}
}while(choice!='N'&& choice!='n');
return 0;
}
Last edited by Sashar400; Sep 26th, 2006 at 2:05 pm. Reason: entire code
•
•
•
•
I have #include<iomanip> header also and it's still not working.I am getting 2 dec places but it's .00 Why is that?Please help.
here is the code
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
also this code is not working ,when I use the [ ] at the end,I am getting an error so I am using () instead but the calculation is incorrect.Please help
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
Last edited by andor; Sep 26th, 2006 at 1:59 pm.
If you want to win, you must not loose (Alan Ford)
•
•
Join Date: Aug 2006
Posts: 9
Reputation:
Solved Threads: 0
entire code
#include <iostream>
#include<iomanip>
#include <cmath>
usingnamespace std;
int main()
{
char choice;
const int arraysize=20;
int num[arraysize];
do
{
cout<<"I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:"<<endl;
cin>>choice;
if(choice =='Y'||choice =='y')
{
cout<<"How many numbers will you enter? (up to 20)?"; cin>>num[arraysize];
for (int j=0;j<num[arraysize];j++)
{
cout<<"Enter Number"<<j+1<<":"; cin>> num[j];
}
cout << " You have entered the following:"<<endl;
for (j = 0; j < num[arraysize]; j++)
{
cout << num[j]<<" ";
}
int sum=0;
for (j=0;j<num[arraysize];j++)
sum+= num[j];
cout<<"\nThe Sum is "<<sum<<endl;
float mean= (sum/num[arraysize]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
//not working
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Varience is " <<var<<endl;
//not working
float sqrtvar=sqrt(var);
cout << showpoint << fixed << setprecision (2);
cout<<"The Standard deviation is "<<sqrtvar<<endl;
//not working
}
}while(choice!='N'&& choice!='n');
return 0;
}
#include <iostream>
#include<iomanip>
#include <cmath>
usingnamespace std;
int main()
{
char choice;
const int arraysize=20;
int num[arraysize];
do
{
cout<<"I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:"<<endl;
cin>>choice;
if(choice =='Y'||choice =='y')
{
cout<<"How many numbers will you enter? (up to 20)?"; cin>>num[arraysize];
for (int j=0;j<num[arraysize];j++)
{
cout<<"Enter Number"<<j+1<<":"; cin>> num[j];
}
cout << " You have entered the following:"<<endl;
for (j = 0; j < num[arraysize]; j++)
{
cout << num[j]<<" ";
}
int sum=0;
for (j=0;j<num[arraysize];j++)
sum+= num[j];
cout<<"\nThe Sum is "<<sum<<endl;
float mean= (sum/num[arraysize]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Mean is "<<mean<<endl;
//not working
float var=((num[0]-mean)*pow(num[0]-mean,2) + (num[1]-mean)*pow(num[1]-mean,2) + + (num[2]-mean)*pow(num[2]-mean,2))/ (num[arraysize-1]);
cout << showpoint << fixed << setprecision (2);
cout<<"The Varience is " <<var<<endl;
//not working
float sqrtvar=sqrt(var);
cout << showpoint << fixed << setprecision (2);
cout<<"The Standard deviation is "<<sqrtvar<<endl;
//not working
}
}while(choice!='N'&& choice!='n');
return 0;
}
Please explain the problem clearly so that we can help you out. Post your entire code along with the problems you are encountering.. whether it is compile time error or run time error or the program is not working as expectd and so on. Maybe then we would be able to help you out.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- iomanip, setprecision - inprecise? (C++)
- Setprecision help please (C++)
- Set Precision in C++.NET? (C++)
Other Threads in the C++ Forum
- Previous Thread: first cannot conver std::string to const char, now runtime error!
- Next Thread: Cannot get PAIR::big to just display greater number
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






