//flex table opened by JP

Click to See Complete Forum and Search --> : C++ 'n' Binary


Spardan
03-06-2003, 12:27 PM
I've just started teaching myself C++, and have put together a simple denary to binary convertor.

The app simply gets the modular of each division by 2 of the target denary and following results, and then pulls them out of an array backwards.

I'm fairly proficient in Object Pascal (Via Delphi) and want to know if there is a way to validate user's input in C++ like the conversion from string to int or real via the 'val' procedure.

For example, if a user enters a number too large or enters non-numeric characters, I'd like to be able to catch that error, and display a relevant message.

Also, just as an Idle Point of Curiosity, can anyone tell me why any number to the power of zero = 1? I've got some ideas but I'm not convinced and I seem to recall that it may all be based on a miscalculation...

Any help with either is, as always, greatly appreciated

Cheers,
Spardan

qball
03-06-2003, 09:17 PM
can anyone tell me why any number to the power of zero = 1?


should be more than idle...

Simple, actually. Exponents are powers of numbers, n to the power of 1, is n. n to the power of -1 is 1/n. n to the power of 0 is n/n=1.

example, take 5.
5**3=125
5**2=25
5**1=5
5**0=?
5**-1=1/5
5**-2=1/25
5**-3=1/125

The difference between 5**2 and 5**1 is divide by 5, thus the difference between 5**1 and 5**0, is divide by 5. 5/5=1.

Can't remember exactly if 0**0=1 is true also, but I think it is...

Are far as the other stuff:

C++ can validate user input as well as any language. I believe Delphi, much like PB has convenient visual IDE, and existing objects that make validation fairly easy (at least in PB). All is not lost, C++,java, basic also have visual IDES and somewhat get close to the level of sophistication of PB, maybe Delphi.

Spardan
03-07-2003, 04:10 AM
Thanks!
It's pretty much what I thought, but it's a lot easier to see why when I'm not arguing about it in the pub...:p

Spardan