![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 4
![]() |
This code is supposed to read values (type double) from user input and place them in an array, using a loop. Easy? No, apparantly not, here's the code:
#include <stdio.h>
int main(void)
{
double user[8]; //user's chosen numbers
int i; //loop counter for user entered numbers
for(i = 0; i <= 7; i++)
{
printf("Enter a number (%d to go): ", 8 - i);
scanf("%lf", &user[i]);
}
return 0;
}When I run this, I enter my first number and get this error: Runtime error R6002 - floating point not loaded Googled the error, but didn't get anything very definitive. But if I use scanf to read the number to 'temp' then on the next line read 'temp' into user[i] - it works fine. scanf("%lf", &temp);
user[i] = temp;It also worked if I just added a line right after scanf, printing what the value of i and user[i] was. scanf("%lf", &user[i]);
printf("user[%d] = %f", i, user[i]);I can't figure out why this doesn't work. And if anyone has issues with me using scanf(), I already know there's better options, but I'm learning from a book and I should technically be able to do this.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me... |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|