Probably simple error - i am a newbie to the world of programming

This is a discussion on Probably simple error - i am a newbie to the world of programming within the C Programming forums, part of the General Programming Boards category; Why does it display a zero at the end? Code: #include "StdAfx.h" #include <stdio.h> #include <math.h> /* Function Prototypes */ ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    5

    Probably simple error - i am a newbie to the world of programming

    Why does it display a zero at the end?


    Code:
    #include "StdAfx.h"
    #include <stdio.h>
    #include <math.h>
    
    /* Function Prototypes */
    
    /*double	ffunction(),
    		dfunction(),
    		calcfunction(),
    		incguess(),
    		displayfound(),
    		displaynotfound();*/
    
    double ffunction(double beta, double gamma, double delta, double x, double fx);
    
    
    int
    main(void)
    {
    	double	b,
    		c,
    		d,
    		guess,
    			
    		ans=0;
    
    
    	printf("please enter b, c, d and guess>\n");
    	scanf("%lf %lf %lf %lf", &b, &c, &d, &guess);
    	ffunction(b,c,d,guess,ans);
    	printf("fx= %f\n", ans);
    	return(0);
    
    }
    double
    ffunction(double beta, double gamma, double delta, double x, double fx){
    	fx = (pow(x,3))+beta*pow(x,2)+gamma*x+delta;
    	return (fx);
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    As far as I can tell you do nothing with the return value of ffunction(). fx inside ffunction is a local variable, it will not affect ans.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Read through Lesson 4: Functions. That should clear up most of your confusion. Additionally, you should set your compiler warnings to max and pay attention to them; that would have pointed out the problem for you.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ newbie needs help with simple conversion programming
    By djayyyyy in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2010, 02:18 PM
  2. simple hello world SERVER/CLIENT
    By goonmaster in forum C Programming
    Replies: 10
    Last Post: 11-27-2009, 02:02 PM
  3. real-world apps in C++ (preferably simple)?
    By Aisthesis in forum C++ Programming
    Replies: 13
    Last Post: 06-12-2009, 01:03 PM
  4. Novice Beginner: Simple hello world wont work
    By hern in forum C++ Programming
    Replies: 8
    Last Post: 06-25-2005, 12:16 PM
  5. Newbie in Game World
    By juniorsp in forum Game Programming
    Replies: 9
    Last Post: 05-13-2004, 08:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21