E
eli m
Whenever i try to multiply big numbers in c++ (for example: 384723987432324 * 23042348372947233240) it always says zero for the answer. Why does it do this?
Whenever i try to multiply big numbers in c++ (for example: 384723987432324 * 23042348372947233240) it always says zero for the answer. Why does it do this?
int main() {"eli m" write:
How about posting the code for the decimal multiply? This sounds more
mysterious to me than your first question.
Whenever i try to multiply big numbers in c++ (for example:
384723987432324 * 23042348372947233240) it always says zero for the
answer. Why does it do this?
Am 17.03.2013 19:20, schrieb eli m:
What does your C++ book say on
- the type(s) of integer literals?
- the values different integer types can represent?
- on arithmetic overflows?
SG
I don't have a book on c++.
And when i also multiply decimals it says zero.
eli m said:int main() {
int mfirstnum, msecondnum;
usigned float ans;
cout << "Type in your first number:";
mfirstnum = getIntx();
cout << "Multiply your first number by:";
msecondnum = getIntx();
ans = mfirstnum * msecondnum;
cout << ans << "\n"; }
int getIntx() {
double x = 0;
while(!(cin >> x)) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Invalid Input. Try again:";
}
return x;
}
:
That is a fragment, not a program.
I don't know why any compiler, of any vintage, would compile that.
Certainly a modern compiler would reject it. I can't think of any good
reason to use whatever it is you have. Decent compilers are free, search
the archives. Get a compiler. Get a book. Read the first part of the
book. Then write a program. Don't use the tab key. Cut and paste; don't
retype when posting.
DevC is an adequate compiler for the kind of thing you want to do if you are
using Windows.
WRT your first question, your numbers are likely too large, the compiler can
do strange things then, possibly including printing a zero. The answer you
want may be hidden someplace in a huge specification I refuse to look at.
Life is too short for that kind of thing.
eli m said:Whenever i try to multiply big numbers in c++ (for example:
384723987432324 * 23042348372947233240) it always says zero for the
answer. Why does it do this?
I am using visual studio 2010.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.