i have a program that i made in my class in Turbo C++ on windows 95or98 i belive. it is made to solve for factorials. th problem is that :
A) it puts it in exponents
B) theres too many numbers to count so i need a way to put commas every 3 digits and i dont know how to do that.
C) any factorials over 1754 give the computer an error that says:
Floating point: overflow
here is my program: -
#include<iostream.h>
-
#include<iomanip.h>
-
#include<conio.h>
-
void main ()
-
{
-
long double bfn=0;
-
long int m=0;
-
char pause;
-
cout<<setiosflags(ios::fixed|ios::showpoint|ios::right)<<setprecision(0);
-
cout<<"type what you want a factorial of"<<endl;
-
cin>>bfn;
-
m=bfn-1;
-
while (m>0)
-
{
-
bfn=bfn*m;
-
m=m-1;
-
cout<<bfn<<endl;
-
}
-
cout<<bfn<<endl<<endl;
-
}
-
how can i fix these problems?
Nov 14 '07
26 9447 NeoPa 32,572
Recognized Expert Moderator MVP
I'm sure digits #8,384 through #9,131 are correct Jos, but are you sure about digit #5,648 (000535258)?
PS. I think he may just get it after your post ;D
@_@ hmmmm
so how would i begin writing a program with a vector/array? i dont quite know the code just yet. but if you do tell me a line of code i would also like to understand it, so please tell me what it means.......>.>
sicarie 4,677
Recognized Expert Moderator Specialist
I would suggest researching vectors and arrays and deciding which one you want, as the datatypes behave differently. Pick the one you feel would be best served in your application, then look it up through Google.
and NeoPa ..... HOW DID YOU FIND THAT? did you compare the entire number?........ ....
NeoPa 32,572
Recognized Expert Moderator MVP
No. I was bluffing mainly. I'm sure Jos's answer is 100% accurate.
I have a text editor that shows what position it's at so counting the length of the number wasn't hard. With so many multiples of ten in the calculation it's obvious that there will be many zeroes at the end of the number.
well that solves the problem.... but i thought i would have fun making this program. i havent much idea as to the code part of what im doing.
NeoPa 32,572
Recognized Expert Moderator MVP
If you ever learned long-multiplication at school, then that's the sort of process you need to be thinking of duplicating. String variables would be required to hold your working variables.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mahuskin |
last post by:
Using Microsoft Visual C++ .NET 69462-270-0000007-18921
When I build the following code in Visual C++ .NET for release, there is a serious optimization error that corrupts the resulting value
double m1 = 1.05
m1 = 1.0/m1
In release image, m1 is much smaller than 1e-9
In debug image, m1 is correct
|
by: Hamish Dean |
last post by:
Hi. To explain this, i'll list some relevant info:
Prog1: A c++ dll, written by me.
Prog2: A c++ dll, written by a 3rd party.
Prog3: A c++ application, written by me.
Prog4: A delphi 7 application, written by me.
Prog5: A delphi 4 application, written by someone else.
Prog1 calls a function from Prog2:
|
by: Mark L Pappin |
last post by:
<puts on Compiler Vendor hat>
I've recently discovered that our compilers don't
make any attempt to handle floating point overflow in add/subtract/
multiply/divide, with the result that programmers who don't range-
check their data can e.g. multiply two very tiny values and end up
with a very large one. This is (AFAICT) quite fine according to the
Standard but is certainly a QoI issue and I'd like to raise ours.
I believe that it's...
|
by: tings |
last post by:
An article states: "In floating point maths, where if you divide by a
sufficiently large number sufficiently often, you will always be able to
reach a value too small to distinguish from zero, given the finite precision
you have."
What happens when "a value too small to distinguish from zero" is reached by
the above division? Underflow?
What does it mean "sufficiently often" since only one division should be
enough to cause underflow...
|
by: Steven Jones |
last post by:
Im just learning C an do not understand why the following code fails.
The while loop apperas to work fine until it bombs out with a
floating point exception. Whats going on?
Thanks
/*
* chapter 5, program 7
* Calculate GCD of two numbers.
| |
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make sense to
punch out from managed code to native code (I was using
IJW) in order to do some amount of floating point work and, if so, what that
certain amount of floating point work was
approximately.
To attempt to do this I made a program that...
|
by: jer006 |
last post by:
Hi I am writing a select statement that has an arithmetic function
inside a case statement that uses logic to decide whether to divide or
multiply and when I run the arithmetic statements outside the case
statement they work fine, but blow up with an overflow error in the
case statement. The select looks like:
SELECT a.acct_cd,
a.crrncy_cd,
a.mkt_val,
c.rate,
|
by: Mukesh_Singh_Nick |
last post by:
Why does floating point have a rounding error? How to work around it?
For example, the following:
flaot f = 1234.12345678F;
printf("%2f\n", f) //prints 1234.123413
and
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |