Solved

Floating point

Posted on 2003-11-18
4
250 Views
Last Modified: 2010-05-18
I have the following code

void main()
{
     struct emp
    {
          char name[20] ;
          float salary ;
    };
    struct emp e[10] ;
    int i ;
    printf ( "Enter the names and salaries of employees\n" ) ;
    for ( i = 0 ; i <= 9 ; i++ )
       scanf ( " %s %f", e[i].name , &e[i].salary ) ;
}
Problem:
I don't have any compilation error.But when i try to execute the program & accept the floating point value, program crashes.I know that this is because of floating point emulator is not initialized and generally happens when we access the float member of the structure before any float variable.
How to initialize this.I am working on VC++ environment.

0
Comment
Question by:umaiyer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
WiB earned 25 total points
ID: 9770159
Just initialize the 'salary' member of structure:

struct emp
    {
          char name[20] ;
          float salary ;
    };
    struct emp e[10] ;
    int i ;
    printf ( "Enter the names and salaries of employees\n" ) ;
   for ( i = 0 ; i <= 9 ; i++ )
   {
      e[i].salary = .0;
      scanf ( " %s %f", e[i].name , &e[i].salary ) ;
   }
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9782179
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question