GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Oct-2003, 20:00
rjd72285 rjd72285 is offline
New Member
 
Join Date: Oct 2003
Posts: 5
rjd72285 is an unknown quantity at this point

need a lot of help


Ok I have a few questions for all of you out there, any help is greatly appreciated.

Is there a way to find the last 6 digits of say a 8 digit number?
Ex. I have a number of 12345678, I want to get 345678.

Also how do I continuosly multiply by a certain number?
What I mean by this is if I want to multiply numbers by 2 all the time.
Ex. I start with the number 4. 4*2 = 8. How do I then multiply 8 by 2 without defining a new variable?
Here's what i got:
CPP / C++ / C Code:
                double newnumber = seed * multi;
	double newnumber2 = newnumber * multi;
	double newnumber3 = newnumber2 * multi;
	cout<<setprecision(10)<<newnumber<<endl;
	cout<<setprecision(15)<<newnumber2<<endl;
	cout<<setprecision(15)<<newnumber3<<endl;
Is there someway I can do this inside of a loop?

Thanks for any feedback
  #2  
Old 26-Oct-2003, 04:42
Dawis Dawis is offline
Awaiting Email Confirmation
 
Join Date: Oct 2003
Location: Latvia, Ogre
Posts: 7
Dawis is an unknown quantity at this point
Hi,
I am not shoure if this is eficient way to do this but if you have for example number 123456789 and you want to get let`s say last 8 numbers then you can do folowing..
CPP / C++ / C Code:
unsigned long  numb=123456789, newnumb=0;
int i=0;
                while (numb>100)
                         {
                           i++;
                           newnumb=newnumb+((numb%10)*i);
                           numb=numb/10;
                          }

after this loop numb should be 12, but newnumb 3456789..
also take into account that unsigned long can hold the numbers only to 2^32, so if you have to deal with really large numbers, it is better to use strings or arrays of characters...

for your second question if I understood it corectly it is quite simple:
you just need to use loop:
CPP / C++ / C Code:
int i=4;
while(your condition)
          {
            i=i*2;
            }
your condition can be any of your choise for example
while (i<16000).. of course such loop is quite useless unless you add something in it`s body, but that is up to you..
hope that helps
  #3  
Old 26-Oct-2003, 12:00
rjd72285 rjd72285 is offline
New Member
 
Join Date: Oct 2003
Posts: 5
rjd72285 is an unknown quantity at this point
How would you go about putting a random number inside of a string? Whenever I try it outputs a bunch of weird characters.

Also the above newnumb does not give last of the number. It gives a 3 digit number, unless I pasted it wrong. Also, if there was a way to reverse the above step would be helpful.

It gives 123456789
then 12345678
and so on.
Last edited by rjd72285 : 26-Oct-2003 at 12:31.
  #4  
Old 28-Oct-2003, 08:21
Dawis Dawis is offline
Awaiting Email Confirmation
 
Join Date: Oct 2003
Location: Latvia, Ogre
Posts: 7
Dawis is an unknown quantity at this point
My aoollogies there was bug i the code...
the code should look like this:
----------------
CPP / C++ / C Code:
unsigned long numb=123456789, newnumb=0;
int i=1;
while (numb>100)
{
newnumb=newnumb+((numb%10)*i);
numb=numb/10;
i=i*10;
}
-----------------

About strings.. I am not too shoure because I have not used strings in c++ too muc, but to my mind you should just randomize number and store the value in some variable, then you can use on of these funtions that converts numbers to strings..
I think one of them was
sprintf.. is should be used something like this..
sprintf(target char buffer, %d, integer);
this funtion is included in on of the standart c libraries not shoure which.. I suggest to read more about this funtion in help or manuali if you have one..
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP!: find window width? Center a <div>? Kingherc Web Design Forum 2 06-Jul-2003 05:25
auto number skyloon MySQL / PHP Forum 1 30-Jun-2003 08:33
How do I find the Unix log file route? jrobbio Web Hosting Forum 4 04-Feb-2003 07:40

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:07.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.