Double precision number help

• 10-16-2012
Magi
Double precision number help
I am new to C Programming and have been doing well so far. I am currently hitting a snag with "double" ie. double precision numbers. The code below is currently working correctly with int integer inputs and I'm trying to get it to instead take in double precision ones and still compile correctly. Help would be great :D

Code:

```#include <stdio.h> int main () {     #define Maxgrade 3     int grade [Maxgrade];     int average, total;     int i;             total=0.0;         for (i=0; i<Maxgrade; i++){         printf ("Enter a grade:  ");         scanf ("%d", &grade[i]);         }             for (i=0; i<Maxgrade; i++)     {         total += grade[i];           }     printf ("\nThe total is %d\n", total);         average = total/3;         printf ("\nThe average is %d\n\n\n", average);             for (i=0; i<Maxgrade; i++){          if (grade[i]<average)       printf ("*");             if (grade[i]>=90)       printf ("%d, A\n", grade[i]);           else if (grade[i]<90, grade[i]>=80)       printf ("%d, B\n", grade[i]);           else if (grade[i]<80, grade[i]>=70)       printf ("%d, C\n", grade[i]);           else if (grade[i]<70, grade[i]>=60)       printf ("%d, D\n", grade[i]);           else if (grade[i]<60)       printf ("%d, F\n", grade[i]);         }             system ("PAUSE");     return 0;     }```
• 10-16-2012
qny
To input a double use "%lf"; to print a double use "%f"

Code:

```/* ... */ double grade[MAXGRADE]; /* Use ALLCAPS for define'd constants */ /* ... */ scanf("%lf", &grade[i]); /* ... */ printf("%f", grade[i]); /* ... */```
• 10-16-2012
TheBigH
Well, for one thing, you need to declare grade, average, and total as double types.
• 10-16-2012
Magi
It worked
Quote:

Originally Posted by qny
To input a double use "%lf"; to print a double use "%f"

Code:

```/* ... */ double grade[MAXGRADE]; /* Use ALLCAPS for define'd constants */ /* ... */ scanf("%lf", &grade[i]); /* ... */ printf("%f", grade[i]); /* ... */```

Thanks a ton, it was the "%lf" scanf that was holding me up :D