Thread: scanf and printf problem?

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    scanf and printf problem?

    Hello all, I am a complete newbie to this programming thing and am taking a intro class at school as required in my curriculum. I am having a problem where my input values are returning values of 0.000000 using a double variable in my code. Here is my code, any help would be much appreciated:
    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    
    {
    double Vt,gravity,cOfDrag,mass,time;
    
    
    printf("This program will use a formula to calculate the velocity\n");
    printf("of a skydiver with a given formula.\n");
    printf("Please enter the mass of the diver in kg in the space provided below.\n");
    scanf("%lf", &mass);
    printf("Please enter the coefficient of drag in kg/s in the space provided below.\n");
    scanf("%lf", &cOfDrag);
    printf("Please enter the time of the flight in seconds in the space provided below.\n");
    scanf("%lf", &time);
    
    gravity=9.8;
    
    Vt=((gravity*mass)/(cOfDrag))*(1-exp(-((cOfDrag/mass))*time));
    
    printf("%lfkg is the value entered for mass.\n", &mass);
    printf("%lfkg/s is the value entered for coefficient of drag.\n", &cOfDrag);
    printf("%lfs is the value entered for time of flight.\n", &time);
    printf("%lfm/s is the velocity.\n", &Vt);
    system("pause");
    
    return 0;
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    In your printf() you are using an ampersand on the variables, that is telling printf to print the address of this variable, which is an integral type (%d). You need to delete the ampersands to print the actual value.

    Also printf()/scanf(), while valid in C++ programs they should be replaced by the C++ streams cin and cout.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Code Please Help
    By Cdre in forum C Programming
    Replies: 3
    Last Post: 02-02-2011, 01:32 AM
  2. Simple XOR Program
    By dolfaniss in forum C Programming
    Replies: 8
    Last Post: 05-24-2010, 01:27 PM
  3. Help again!!
    By ewic0190 in forum C Programming
    Replies: 1
    Last Post: 03-19-2010, 06:56 PM
  4. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  5. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM