Thread: scanf not working

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    56

    scanf not working

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    
     
     
    int main()
    {
    double loop_counter = 2, PWR = 0, result = 0, new_counter = 2; 
    printf("enter an interger:\n ");
    scanf("%f", &PWR);
    result = pow(new_counter, PWR);
    printf("%f\n", result);
    system("pause");
    return 0;
     
     
     
     
     
     
    }
    No matter what value i put in there, it's always 0.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    When using scanf() the "%f" format specifier is used for a float, not a double. You'll need to read the documentation and select the proper format specifier for your double.

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    56
    Oh wow! Thank you!
    It was supposed to be
    Code:
    lf
    .
    Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf is not working
    By learning_grc in forum C Programming
    Replies: 9
    Last Post: 11-16-2011, 04:09 PM
  2. Working with strings [using scanf()]
    By Luponius in forum C Programming
    Replies: 4
    Last Post: 04-26-2011, 10:27 AM
  3. why scanf() dont working?
    By RAJJUMOTE in forum C Programming
    Replies: 10
    Last Post: 12-16-2007, 10:29 PM
  4. Every other scanf not working
    By Rob20050 in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 12:48 AM
  5. Why isn't this working? using scanf and stuff
    By jumboman in forum C Programming
    Replies: 2
    Last Post: 07-17-2003, 01:56 PM