?
Solved

Floating point

Posted on 2003-11-18
4
Medium Priority
?
252 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 75 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

Independent Software Vendors: 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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