PDA

View Full Version : Arrays in C



daniel of sarnia
October 27th, 2007, 10:15 AM
Hey I'm learning C, and I was hoping someone could help me out trying to make an array that stores then prints doubles. I thought it would be easy, but I guess I've messed up somewhere. It's odd to because I can make it work with and int.




#include <stdio.h>

#define SIZE 10

int main(void)
{

double val[SIZE], ans;
int i;



for( i=0 ; i<SIZE ; i++)
{
printf("\nEnter a double number: ");
scanf("%f \n", &val[i]);
}


for( i=0 ; i<SIZE ; i++)
printf("%f \n", val[i]);

return 0;
}


Thanks in advance, I think it's something really simple to. But I can get it to work :confused:

WakkiTabakki
October 27th, 2007, 11:01 AM
Since your using double your formatting string should be %lf (as in Long Float), e.g

scanf("%lf", &val[i]);

Same goes for the printf-line, ofcourse...

/N

daniel of sarnia
October 27th, 2007, 11:04 AM
Thank so much, ahhh I've read the before too. Little things I for get make me crazy hahaha