![]() |
|
|
#1 |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Which Algorithm To Use?
Say I have a number that is "x" int long. That I want to divide it by a number that as equally as long.
x == "14" So what algorithm should I use with C++? If you need further information, please ask. Thanks, Chris
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay Last edited by Munki; 11-06-2009 at 08:01 PM. |
|
|
|
| The Following User Says Thank You to Munki For This Useful Post: |
|
|
#2 |
|
Administrator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
|
umm .. give an example ?
|
|
|
|
|
|
#3 |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
In a C++ Calculator I want to divide 65,000,654,999,000 by 43,998,897,987,888
I wouldnt be asking such a out of the blue question if I wasnt trying to prepare for my next school year. Computer Science requires me to learn to program. Thought I would get a jump on it. Ive tinkered with it before, but nothing as serious as this is going to be.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
#4 |
|
Administrator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
|
convert to double and divide? or do you need more precision ?
Code:
const char a[]="65000654999000"; const char b[]="43998897987888"; double c=atof(a)/atof(b); ok that's standard c, not c++, but the basic q is do you want to convert and divide or do you want to divide the "strings" ? in that case a good start would be the same approach how you divide numbers on paper Last edited by W1zzard; 11-06-2009 at 06:55 PM. |
|
|
|
| The Following User Says Thank You to W1zzard For This Useful Post: |
|
|
#5 |
![]() |
wow w1zz, you are very hardcore. I dont even have a C compiler on this machine! pretty much nothing before 1973 on here :P
![]()
__________________
A+, N+, S+, MCSE. Heatware my FS thread STEAM ID Name: furi0nst0rmrage (0s are zeros) |
|
|
|
|
|
#6 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
Well obviously im a n00b, because I used single quote for a int where I needed to use a double quote in my OP. I noticed you turned my numbers into ASCII then, ASCII into Float, im still trying to process how the computer will see it. Like what "65000654999000" would look in ASCII.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#7 |
|
Administrator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
|
"65000654999000" looks like "65000654999000" .. thats what a string is .. when you put it into "
single quote defines a single character: char ch='x'; other in-memory representations, educational, you will probably never need to know why it looks like that float a=65000654999000; ![]() double a=65000654999000; ![]() uint64 a=65000654999000; ![]() |
|
|
|
|
|
#8 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
Okay when in integer form its just the number, period. How would I go about changing char ' 65000654999000' ?
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#9 |
|
Administrator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
|
you can not create a single ascii character that contains 65000654999000 .. a single character is just a single character, not several characters
|
|
|
|
|
|
#10 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
I understand, but could you create an array of char to form said num?
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#11 |
|
TPU Hit Squad Member
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts
|
He did that in post #4 using
const char[] a = "123456789" The brackets mean the variale or constant (in this case 'a') is an array.
__________________
53452340602F55453253602E35572D$20
|
|
|
|
|
|
#12 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
ASCII is a set chart of conversions? Im a complete n00b here, but im going to have to bite the bullet and try to learn even if im asking questions that have no meaning. I wanted to make a C++ calculator that did 14 digit numbers. So when he did Const Char a[] = " 12345678 " Char is referring to ASCII. ASCII does not contain such a number. 65000654999000 is a 6 byte number. and W1zzard used a double which can handle up to 8 Bytes correct? and the double c=atof(a)/atof(b); double c == answer? atof == ASCII to Float So in this case the ASCII code is 'a' for "65000654999000" and 'b' is for "43998897987888" and the \ is telling it to divide Array 'a' by array 'b'? Can someone verify this for me?
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay Last edited by Munki; 11-06-2009 at 08:48 PM. |
|
|
|
|
|
|
#13 |
|
TPU Hit Squad Member
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts
|
When you enclose something in double quotes (like "1234") it takes it as a string literal, not the value of the numbers. So so the computer sees "1234" as ascii 49,50,51 & 51.
When you send a string into a character array it simply breaks the string into it's respective characters. char[] A = "1234" So A[0] will be equal to ascii 49 and visually represented as the number 1 A[1] will be ascii 50 etc. etc. In order to do mathematical calculations on the string literal you have to cast it back to a number. That is what atof(string) did. atof means ascii to floating point number.
__________________
53452340602F55453253602E35572D$20
|
|
|
|
|
|
#14 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
Example for verification: Const Char A[] -= "1234" Char A[0] = 1 *ASCII* Char A[1] = 2 Char A[2] = 3 Char A[3] = 4 Back on in about 30 mins.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#15 | |
|
TPU Hit Squad Member
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts
|
Quote:
__________________
53452340602F55453253602E35572D$20
|
|
|
|
|
|
|
#16 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
?
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#17 |
|
TPU Hit Squad Member
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts
|
No. When you doing calculations you will have to do them in a type that is numerical (int, float, double). When you are doing input and output you will need to display them in a string or character format. You will simply have to convert between them to accomplish what you want.
So for instance let say you ask the user for two numbers. They type in 10 and 20 on the keyboard. This will be in string format "10" and "20" Convert them to numeric format. Int a = atoi("10") Int b = atoi("20") Add them together... Int c = a + b output the result char[] output = itoa(c) You must learn the basic types of the language and how they are used and converted. It's not hard, it will just take some studying. As always, we are here to help.
__________________
53452340602F55453253602E35572D$20
|
|
|
|
|
|
#18 |
![]() |
For anyone interested in doing really really really big arithmetic...
There is a library out there called "The GNU Multiple Precision Arithmetic Library" which lets you perform arithmetic on arbitrary length numbers ![]() You can do cool stuff like: Code:
mpz_t n; mpz_init_set_str (n, "184764827574746458753962934628956823764982346829348264826583465893465389465262894689326583946589346583465834", 10); mpz_t pie; mpz_init_set_str (pie, "3141592653589793238462643383279502884", 10) // n = n - pie; mpz_sub (n, n, pie); |
|
|
|
|
|
#19 |
![]() Join Date: Jun 2007
Location: Miami, FL
Posts: 4,594 (5.08/day)
Thanks: 324
Thanked 871 Times in 560 Posts
|
WOW! There is so much math in this thread it makes my butthole pucker!
__________________
A monster lies in wait for me. A stew of pain and misery, But fiercer still in life and limb. Is me that lies in wait for him. Rate TheMailBox |
|
|
|
|
|
#20 |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Well I am trying, last night I didnt come back to TPU because I had my head in a C++ book that deprived me of $35
Sure hope it pays off....im working on a calculator that uses this as I type this.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
#21 |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Okay well, im about to install my compiler and see how well my first program works. Wish me luck, God knows im going to need it.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
#22 |
![]() Join Date: Nov 2008
Location: Sydney, Australia
Posts: 553 (1.45/day)
Thanks: 311
Thanked 65 Times in 64 Posts
|
Good luck..wanna learn C++ too so I can make some hardcore programms and send viruses to those bitches in year 6. 3 More years to year 10, 3 More years to year 10, 3 More years to year 10...
__________________
“Why would you do that, o i have a question can you uninstall and install any graphics card while the OS is runing and your rig is runing, i just always shit it down before i add, change, or move a video card in the x16 slots.” -3volvedcombat
|
|
|
|
|
|
#23 | |
![]() Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
|
Quote:
![]() BTW the program worked Just a bit messy. Gotta do some cleanup.
__________________
![]() Referances: Heatware: ipphreak ebay: mollymay506 amazon: insane_monkay |
|
|
|
|
|
|
#24 | |
![]() Join Date: Jun 2007
Location: Miami, FL
Posts: 4,594 (5.08/day)
Thanks: 324
Thanked 871 Times in 560 Posts
|
Quote:
![]()
__________________
A monster lies in wait for me. A stew of pain and misery, But fiercer still in life and limb. Is me that lies in wait for him. Rate TheMailBox |
|
|
|
|
|
|
#25 |
|
TPU Hit Squad Member
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts
|
Having a book for reference will come in handy, Munki. It's easier that always having to search through the net for answers for basics.
As soon as you get some code going, post it here so we can take a look at it and help you out. ![]() PS. I have no idea what Onafets is talkiing about either. lol
__________________
53452340602F55453253602E35572D$20
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which audio to use | theonetruewill | General Hardware | 6 | 07-10-2007 11:54 PM |
| Which program to use | trt740 | Overclocking & Cooling | 4 | 05-29-2007 08:56 PM |
| Which to use | gerrynicol | Graphics Cards | 20 | 08-29-2006 08:32 PM |
| Which should i use? | BigD6997 | Graphics Cards | 5 | 07-06-2006 12:48 AM |