Thread: Debug Error

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    36

    Debug Error

    I am having trouble with this program. It compiles, builds, and links but when I execute it I am having a problem inputing the double. Please help! MS Visual Studio 6.


    Code:
    	#include <stdio.h>
    	#include <float.h> 
    	
    	int main()
    	{
    	int bookID, volumeOH, expectedEN;
    	int costPC;
    	char R, S, N, O; 
    
    	printf ("*********************************************************\n");
    	printf ("WELCOME TO THE JLH05G BOOKSTORE ORDER ESTIMATION PROGRAM!\n");
    	printf ("*********************************************************\n");
    
    
    	printf ("\nPlease Enter The Books Cost Per Copy: \n");
    	scanf ("%d", &costPC);
    
    	printf ("\nPlease Enter The Book ID Number: \n");
    	scanf ("%d", &bookID);
    
    	printf ("\nPlease Enter The Volume On Hand: \n");
    	scanf ("%d", &volumeOH);
    
    	printf ("\nPlease Enter The Expected Enrollment: \n");
    	scanf ("%d", &expectedEN);
    
    	
    
    	return 0;
    	}

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    36
    Code:
    	
            #include <stdio.h>
    	#include <float.h> 
    	
    	int main()
    	{
    	int bookID, volumeOH, expectedEN;
    	int costPC;
    	char R, S, N, O; 
    
    	printf ("*********************************************************\n");
    	printf ("WELCOME TO THE JLH05G BOOKSTORE ORDER ESTIMATION PROGRAM!\n");
    	printf ("*********************************************************\n");
    
    
    
    	printf ("\nPlease Enter The Book ID Number: \n");
    	scanf ("%d", &bookID);
            
    	printf ("\nPlease Enter The Books Cost Per Copy: \n");
    	scanf ("%lf", &costPC);
    
    	printf ("\nPlease Enter The Volume On Hand: \n");
    	scanf ("%d", &volumeOH);
    
    	printf ("\nPlease Enter The Expected Enrollment: \n");
    	scanf ("%d", &expectedEN);
    
    	
    
    	return 0;
    	}
    This is the code I was talking about. I accidently posted one version I had been troubleshooting with.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    int costPC;
    Code:
    scanf ("%lf", &costPC);
    Match the format specifier with the data type (or vice-versa).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    36

    Sorry

    I was really tired when I posted, this is the code that I am having problems with...

    Code:
     
            #include <stdio.h>
    	#include <float.h> 
    	
    	int main()
    	{
    	int bookID, volumeOH, expectedEN;
    	double costPC;
    	char R, S, N, O; 
    
    	printf ("**************************************************  *******\n");
    	printf ("WELCOME TO THE JLH05G BOOKSTORE ORDER ESTIMATION PROGRAM!\n");
    	printf ("**************************************************  *******\n");
    
    
    
    	printf ("\nPlease Enter The Book ID Number: \n");
    	scanf ("%d", &bookID);
            
    	printf ("\nPlease Enter The Books Cost Per Copy: \n");
    	scanf ("%lf", &costPC);
    
    	printf ("\nPlease Enter The Volume On Hand: \n");
    	scanf ("%d", &volumeOH);
    
    	printf ("\nPlease Enter The Expected Enrollment: \n");
    	scanf ("%d", &expectedEN);
    
    	
    
    	return 0;
    	}
    I had the doulble declared right and accidently posted the version I had been experimenting where I switched to an int for testing. Everything looks right in syntax, there are no errors. The problem is when I enter the double costPC the program crashes and if I ignore it says "runtime error 6002 floating point not loaded" on the execution screen.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    36
    Thanks alot Dave.

    I added this to the code and everything seems fine.

    Code:
    double costPC = 0
    Apparanly initializing the variable to 0 makes everything good. Any idea why it works now?

    Thanks again

    Justin

  7. #7
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    Quote Originally Posted by jlharrison
    Any idea why it works now?
    My guess would be that the initialization of the double variable is somehow causing the compiler to notice that you're doing floating point calculations, thus causing floating point support to be linked in.
    Insert obnoxious but pithy remark here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  4. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM