setprecision

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 9
Reputation: Sashar400 is an unknown quantity at this point 
Solved Threads: 0
Sashar400 Sashar400 is offline Offline
Newbie Poster

setprecision

 
0
  #1
Sep 26th, 2006
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;

}
Last edited by Sashar400; Sep 26th, 2006 at 2:05 pm. Reason: entire code
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: setprecision

 
1
  #2
Sep 26th, 2006
Originally Posted by Sashar400 View Post
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]);
If you want help you need to post the whole code. Read this
Last edited by andor; Sep 26th, 2006 at 1:59 pm.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 9
Reputation: Sashar400 is an unknown quantity at this point 
Solved Threads: 0
Sashar400 Sashar400 is offline Offline
Newbie Poster

setprecision

 
1
  #3
Sep 26th, 2006
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;

}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: setprecision

 
0
  #4
Sep 26th, 2006
lovely code -- but what is your question ? please edit your post to include code tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: setprecision

 
1
  #5
Sep 26th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: setprecision

 
1
  #6
Sep 26th, 2006
I suggest you do a google search of setprecision and pow.

I think pow expects a double somewhere. So you'll have to write pow(2,3) and pow (2.0,3.0) or something? Not to sure.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC