It's seem cannot print out! Help! Noob Here.

Sep 11, 2012 at 1:02pm
Hello. I'm an engineering student and i have a problem with my program that I encode. It seem's that it can not print out the results. This program is all about finding the roots of a specific function using Regula Falsi Method.

This is my program:

#include<iostream>
#include <stdlib.h>
#include<cmath>
using namespace std;
int main()
{
double a,b=0,c,d=0,e=0,f=0,g,i,t=0.000010,p=3.1416;
cout<<"Choose from the two equation to find its roots:\n 1:x^3-7x^2+6x+5 \t 2: 3x+sinx+e^x\n";
cin>>g;
if(g==1)
{
a=1;
c=2;
for(i=1;e>=t;i++)
{
d=pow(a,3)-(7*pow(a,2))+(6*a)+5;
f=pow(c,3)-(7*pow(c,2))+(6*c)+5;
b=(c*d)-(a*f)/(d-f);
e=pow(b,3)-(7*pow(b,2))+(6*b)+5;
cout<<a<<b<<c<<d<<e<<f;
if(d*e>0)
{c=b;}
else if (d*e<0)
a=b;
}
}
else if (g==2)
{
a=0;
c=1;
for(i=1;e>=t;i++)
{
d=(3*a)+sin(a*p/180)-exp(a);
f=(3*c)+sin(c*p/180)-exp(c);
b=(c*d)-(a*f)/(d-f);
e=(3*b)+sin(b*p/180)-exp(b);
cout<<a<<b<<c<<d<<e<<f;
if(d*e>0)
{c=b;}
else if (d*e<0)
a=b;
}
}

system("pause");
return (0);
}


Please help me.. Thank you.
Sep 11, 2012 at 1:28pm
for(i=1;e>=t;i++)

This for loop will repeat as long as e is greater than or equal to t. What is the value of e and the value of t the first time this loop is reached? So how many times will it loop?
Sep 11, 2012 at 1:33pm
Does the program require that you put the cout inside the for loop? If not simply putting a cout statement after the for loop finishes should do the trick.

EDIT: not sure why you're using a for loop, the loop will run until a condition is met, which is why a while loop will suit the program better. Using a while loop the program ran fine.
Last edited on Sep 11, 2012 at 1:42pm
Topic archived. No new replies allowed.