Solved

Floating point

Posted on 2003-11-18
4
246 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

23 Experts available now in Live!

Get 1:1 Help Now