0

Here is the code I'm using,

#include <stdio.h>
int main () {
    /* variable definition: */
    double sidea, sideb, sidec;
    /* Prompt user for side a */
    printf("Enter length of side a of the triangle: \n"); // Input the base
    scanf("%f", &sidea);
    /* Prompt user for side b */
    printf("Enter the length of side b of the triangle: \n"); // Input the base
    scanf("%f", &sideb);
    /* Prompt user for side c */
    printf("Enter the length of side c of the triangle \n");
    scanf("%f", &sidec);
    // Calculate the Perimeter
    double perimeter=  (sidea + sideb + sidec);
    // Print the result
    printf("The perimeter is : %f \n", perimeter);
    return 0;
}

Input data: 4.6 7.5 5.8

I can't for the life of me figure out why any values used for input result in 0.000000. Using float seems to work just fine. What am I missing. Thanks!

jwdonahue
  • 6,199
  • 2
  • 21
  • 43

1 Answers1

1

Use %lf format specifier for reading double.

Also you may note that using wrong format specifier is UB.(Undefined behavior).

user2736738
  • 30,591
  • 5
  • 42
  • 56