Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2005, 2:10 PM   #1
tommclaughlan
Newbie
 
Join Date: Jan 2005
Posts: 3
Rep Power: 0 tommclaughlan is on a distinguished road
calculating phi. problem

#include <cstdlib>
#include <iostream>
#include <stdint.h>
#include <io.h>
#include <math.h>
int main()


    {
    double phi = 5;

    for (long int n = 0; n < 5000; n=n+1)


        {
        phi=(1/phi)+1;
        }
    printf("Estimated PHI value: %f "),phi;
    scanf("press enter: %d");
    return 0;
}

i want this to return a value which is approximately phi (1.618033989...) but it just gives me "Estimated PHI value: 0.00000000"
any help would be appreciated
tommclaughlan is offline   Reply With Quote
Old Feb 1st, 2005, 3:13 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You have the printf statement messed up - phi is outside the brackets. You should have:
printf("Estimated PHI value: %f ", phi);
And BTW, what the hell is stdint.h?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 1st, 2005, 3:16 PM   #3
Hockeyman
Programmer
 
Hockeyman's Avatar
 
Join Date: Jan 2005
Location: Vancouver, Canada
Posts: 60
Rep Power: 4 Hockeyman is on a distinguished road
Send a message via MSN to Hockeyman
You've got the variable outside the printf statement...
try:
printf("Estimated PHI value:%f ", phi);
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~

Hockeyman is offline   Reply With Quote
Old Feb 1st, 2005, 3:17 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Beat ya to it. :p
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 1st, 2005, 3:32 PM   #5
Hockeyman
Programmer
 
Hockeyman's Avatar
 
Join Date: Jan 2005
Location: Vancouver, Canada
Posts: 60
Rep Power: 4 Hockeyman is on a distinguished road
Send a message via MSN to Hockeyman
Ooble - by seconds =^)

Tomm - is that code part of a larger program? If not, you don't need most/all of those include statements...and I'm surprised that printf works without stdio.h (although I'm not sure what's in some of those libraries so it might be in there as well)
__________________
~ You know, Hobbes, some days even my lucky rocketship underpants don't help. ~

Hockeyman is offline   Reply With Quote
Old Feb 1st, 2005, 4:12 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I believe it's in io.h as well.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 2nd, 2005, 5:49 PM   #7
tommclaughlan
Newbie
 
Join Date: Jan 2005
Posts: 3
Rep Power: 0 tommclaughlan is on a distinguished road
i hope to expand this program to calculate many significant figures of phi, which is the solution to the equation x*x-x-1=0.
i'm not really an experienced programmer so i just learned from online tutorials and such so i don't really know what those include things are, etc.
tommclaughlan is offline   Reply With Quote
Old Feb 3rd, 2005, 8:20 AM   #8
suriyaa
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 suriyaa is on a distinguished road
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
double phi =5;
for( long int n=0;n<5000;n++) //n++ is same as n=n+1;
{
phi=(1/phi)+1
}
cout<<"estimated phi values is : "<<phi; \\printf("estimated phi value is :%f",phi);
getch();\\to make wait
}
suriyaa is offline   Reply With Quote
Old Feb 14th, 2005, 12:40 PM   #9
L F Permenter
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 L F Permenter is on a distinguished road
PHI - the Golden Ratio

// Phi, the Golden ratio
// We can calculate Phi without recursion or iteration,
// as it is one solution to a quadratic equation.
// phi = 1/2 = 1/2 *(SQRT(5)).

double PHI = 0.5 +pow(5.0,0.5)/2.0;

// print out in the normal manner

//

Quote:
Originally Posted by tommclaughlan
#include <cstdlib>
#include <iostream>
#include <stdint.h>
#include <io.h>
#include <math.h>
int main()


    {
    double phi = 5;

    for (long int n = 0; n < 5000; n=n+1)


        {
        phi=(1/phi)+1;
        }
    printf("Estimated PHI value: %f "),phi;
    scanf("press enter: %d");
    return 0;
}

i want this to return a value which is approximately phi (1.618033989...) but it just gives me "Estimated PHI value: 0.00000000"
any help would be appreciated
L F Permenter is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:15 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC