Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Nov 1st, 2005, 12:58 AM   #1
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 4 bivhitscar is on a distinguished road
Angry Problems reading a double into an array using scanf()

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...
bivhitscar is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC