Solved

Floating point

Posted on 2003-11-18
4
245 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
4 Comments
 
LVL 3

Accepted Solution

by:
WiB earned 25 total points
Comment Utility
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
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now