-
C++ error, "Floating Point: Overflow
I am trying to learn C++. I am using the Borland version 4.52 that came with a "Teach yourself C++ in 21 Days" tutorial. I get a pop-up error window with the "Floating Point: Overflow" message when I input any number with a decimal value at the prompt "Enter the first real number".
Here is the code:
//simple C++ program to illustrate simple mather operations
#include <iostream.h>
main()
{
int int1, int2;
long long1, long2, long3, long4, long5;
float x, y, real1, real2, real3, real4;
cout<<"\nType first integer : ";
cin>>int1;
cout<<"\nType second integer : ";
cin>>int2;
cout<<"\n";
long1 = int1 + int2;
long2 = int1 - int2;
long3 = int1 * int2;
long4 = int1 / int2;
long5 = int1 % int2;
cout<<int1<<" + "<<int2<<" = "<<long1<<'\n';
cout<<int1<<" - "<<int2<<" = "<<long2<<'\n';
cout<<int1<<" * "<<int2<<" = "<<long3<<'\n';
cout<<int1<<" / "<<int2<<" = "<<long4<<'\n';
cout<<int1<<" mod "<<int2<<" = "<<long5<<'\n';
cout<<"\n\n";
cout<<"Type the first real number : ";
cin >> y;
cout<<"Type the second real number : ";
cin >> x;
cout << "\n";
real1 = x + y;
real2 = x - y;
real3 = x * y;
real4 = x / y;
cout << x << " + " << y << " = " << real1 << '\n';
cout << x << " - " << y << " = " << real2 << '\n';
cout << x << " * " << y << " = " << real3 << '\n';
cout << x << " / " << y << " = " << real4 << '\n';
cout << "\n\n" ;
return 0;
}
Aside from advising me to get a "real" compiler, can anyone tell me why I am getting the error? I checked for the Pentium FDIV flaw, and mine is OK. I am befuddled.
Asp
-
Senior Member
there is nothing wrong with your program I copied the script to visual C++ and it compiled and ran fine. When I entered a decimal value for the "Enter the first real value" prompt it worked fine.
I would say there has to be something wrong with your compiler try a different one if you can.
-
Banned
I concur.
Works for me in both Turbo C++ 1.0 (ancient) and Borland C++5.5.
-
Can you make int1 and int2 floating data type (float or double). In MS Visual C++, I believe it simply ignores anything beyond and including the decimal pt. Maybe Borland doesn't do that.
This is just a guess.
-
Originally posted by Bula
Can you make int1 and int2 floating data type (float or double). In MS Visual C++, I believe it simply ignores anything beyond and including the decimal pt. Maybe Borland doesn't do that.
This is just a guess.
I went back and tried it both ways, with the int1 and int2 defined as float and then as double. I can declare them as float or double, but if I input anything other than an integer, I get the overflow error.
I have installed the only patch Borland has for 4.52, and that didn't work (I didn't think it would, it has more to do with the Win32 API printer functions than with any math functions.
I think I will try installing the program again. If that doesn't work, I will have to get a compiler that works.
Thank you, all.
-
Here is what I have been able to find out:
FAQ579C.txt Floating Point overflow error in Windows 95
Category :IDE
Platform :Windows 95
Product : BC++4.5x BC++5.x TC++Win4.5
Question:
I have recently installed Borland C++ 4.5 on my computer, and
every time I run a program compiled by BC++ which includes
entering data of the 'double' data type, I get the error message
'Floating Point error: Overflow'. Example:
#include
void main()
{
double In;
cout << "\n Enter a number: ";
cin >> In;
cout << "\n You entered " << In;
}
This program runs perfectly fine if I for instance enter the
number 54 when prompted, but if I enter 4.5, for instance, I get
an overflow error.
Answer:
This error occurs if you have the Microsoft Windows 95 Plus Pack
installed without Service Pack 1. There is a bug in a component
of the System Agent that causes this problem. You can do one of
two things to fix the problem:
1) Get Service Pack 1 from www.microsoft.com and install it,
2) Turn off the System Agent. You can find it from
Start|Programs|Accessories|System Tools. Go to the Advanced menu
and choose "Suspend System Agent" or "stop using System Agent".
7/2/98 10:32:32 AM
If you are using Win98, Task Scheduler replaces System Agent. I have turned my Task Scheduler off, but still get the error if I input anything other than an integer. If I define x=1.25 and y=2.58, I get the expeced results. Likewise, if I insert a function x=x/100000, y=y/100000 and then enter an integer, it still handles floating precision numbers. I just can't input them with a cin statement.
I am checking with Microsoft to see if there is a patch for this.
Thanks to all who have helped
Asp
-
Banned
yo i have a GREAT compiler for learning on, its DevC++ 4, if your script has an error in it, it will tell you exactly what line the error is on and why its wrong and wont let you compile until you fix it
its just an install and run program, no screwing around with 'bins' or whatever the hell that borland thing has going on
contact me on ICQ at: 110492672
hey im just wondering but what does this mean in your script?long5 = int1 % int2;
i have never dealt withthe '%' command before as a function and not part of a int, double or float
Last edited by [shawn@localhost /home]#; 10-27-2001 at 04:31 AM.
-
Originally posted by [shawn@localhost /home]#
hey im just wondering but what does this mean in your script?long5 = int1 % int2;
i have never dealt withthe '%' command before as a function and not part of a int, double or float
the '%' is a "modulus" command. It allows you to return the remainder after deviding one number by another number. I am too new to programming to have any idea why that would be necessary.
Thanks for the tip on the compiler. I don't have an ICQ account yet. I will have to get one, as there are many people I deal with who communicate that way.
ASP
-
Banned
ICQ rocks man, my buddy gave me a copy of some game thing over it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke
|
Bookmarks