473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Could someone check the reason why the decimal output of my code does not change.

Please check my code why it isn't producing result that has decimal places that i want?
Expand|Select|Wrap|Line Numbers
  1. int main ()
  2. {
  3. double a,b,fa,fb,fc,c,f,x,t,g,y,temp;
  4. int max=500;
  5. int i,z;
  6. cout<<"Enter tolerance: ";
  7. cin>>y;
  8. cout<<"Enter how many decimal places: "<<endl;
  9. cin>>z;
  10. cout<<"Enter the domain:"<<endl;
  11. cout<<"a= ";
  12. cin>>a;
  13. cout<<"b= ";
  14. cin>>b;
  15.  
  16. if (a>b)
  17. {
  18. temp=a;
  19. a=b;
  20. b=temp;
  21. }
  22.  
  23. for (i=0;i<=max;i++)
  24.  
  25. {
  26. fa=a*a*a-3*a-1;
  27. fb=b*b*b-3*b-1;
  28. t=1.0;
  29. c=(b*fa-a*fb)/(fa-fb);
  30. fc=c*c*c-3*c-1;
  31. f=(c-t)/c;
  32. g=fabs(f);
  33.  
  34. if (g <= y)
  35.  
  36. break;
  37.  
  38. else 
  39. if (fa*fc > 0.0)
  40. {
  41. t=c;
  42. a=c;
  43. }
  44. else
  45. {
  46. t=c;
  47. b=c;
  48. }
  49.  
  50. }
  51. if (c<=b && c>=a)
  52. cout<<c<<setprecision(z)<<fixed<<end…
  53. else
  54. cout<<"There's no real root between "<<a<<" and "<<b<<endl;
  55.  
  56.  
  57.  
  58. system ("pause");
  59. return 0;
  60. }
Jul 28 '11 #1
1 1396
weaknessforcats
9,208 Expert Mod 8TB
setprecision has two meanings. A: for floating-point default the value specifies the number of digits before and after the decimal point. B: For fixed (scientific) notation the value specifies the number of decimal places.

The setprecision I see appears to to be case A above.
Jul 28 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Sue | last post by:
Hello! I am back with another question. Remember I am a new JavaScript student and I am aware that this code does not check for all the possibilities and that as a "NEW" JavaScript student I am...
11
by: 1111111111 | last post by:
Here is what I have so far... User is to enter 2 integers. One digit at a time. After that I have to print out what the user entered, and then add the two together. Example: Enter First Integer...
6
by: Brian Miller | last post by:
I've been constructing an ASP.Net application using the 1.1 framework, and have been using Web Matrix for development purposes. Now that my application is near completion, I wanted to see if I can...
0
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
5
by: Mike_August | last post by:
Could someone help me out with the following? I've got 1)an xml file 2)an xsl 3)a schema My namespaces are as follow molecular_db.xml
8
by: Bart | last post by:
Could someone explain me what is wrong with this code ? I gives me a compile error: Error 1 Use of unassigned local variable 'fileStreamObject' C:\Documents and Settings\Bart\Local...
5
by: patelxxx | last post by:
I have a FORM with allows user to input their name and then user clicks submit which this goes to my .cgi script. Can someone check this .cgi script as the results are not being displayed as...
3
by: shapper | last post by:
Hello, I have two tables: Polls and Options: Poll PollID, Question Options OptionID, PollID, Answer I want to select a Poll given its ID and all Options associated to it. Options should...
3
Lovro Mirnik
by: Lovro Mirnik | last post by:
Hello, I've been working with Dates today and the entire thing baffles my mind. I'm looking for an explanation of this simple code. DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.