Math Functions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Math Functions

 
0
  #1
Aug 12th, 2006
Hello Everyone,

This is my first post, I am very new to C++, infact only touched it once before today, so I need some help.

I am trying to genorate a big number, This number isn't actualy possible to genorate (Googolplex) but I want to program to keep multiplying itself by 10, until the stop button is pressed.

I have a rich text box set up, where I want the outputted number to go in real time.

Then, I have another rich text box (On another tab) Where, I want the index form of the number to be shown.

First problem, is the max number able to be genorated in C++ 2,147,483,647?? I read this in a tutorial...

Second, How can I output everything done in real time to a rich text box? Then, I guess I need to count the zero's and put 10^amout on zero's in the other box.


I don't want to be spoonfed, I need to learn how to use C++ so any tips/helps would be great, a point in the right direction, ect.

Thanks for your time,

Brendan.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Math Functions

 
0
  #2
Aug 12th, 2006
Slightly mincing the order...
Originally Posted by Wreef
Hello Everyone,

This is my first post, I am very new to C++, infact only touched it once before today, so I need some help.
Welcome!

Originally Posted by Wreef
First problem, is the max number able to be genorated in C++ 2,147,483,647?? I read this in a tutorial...
Well, that tutorial should have said this was a platform-specific limitation, not one of the language, but that's splitting hairs.

Originally Posted by Wreef
I don't want to be spoonfed, I need to learn how to use C++ so any tips/helps would be great, a point in the right direction, ect.
I applaud that attitude, it is all too infrequent.

Originally Posted by Wreef
I am trying to genorate a big number, This number isn't actualy possible to genorate (Googolplex) but I want to program to keep multiplying itself by 10, until the stop button is pressed.
Perhaps consider adding zeros to a string.

Originally Posted by Wreef
Second, How can I output everything done in real time to a rich text box? Then, I guess I need to count the zero's and put 10^amout on zero's in the other box.
Originally Posted by Wreef
I have a rich text box set up, where I want the outputted number to go in real time.

Then, I have another rich text box (On another tab) Where, I want the index form of the number to be shown.
It sounds like you know some API stuff before the language proper. This make it a little more confusing trying to gauge what recommendation(s) may be at your level [API stuff is generallyl out of mine.] Perhaps you could post a minimal snippet of compileable code to help others help you.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Re: Math Functions

 
0
  #3
Aug 12th, 2006
Originally Posted by Dave Sinkula
Slightly mincing the order...
I applaud that attitude, it is all too infrequent.
Haha, Yeah, Well unlike alot of people I know, I love to learn!

Perhaps consider adding zeros to a string.
Is there a tutorial anywhere where I can learn how to do this?

It sounds like you know some API stuff before the language proper. This make it a little more confusing trying to gauge what recommendation(s) may be at your level [API stuff is generallyl out of mine.] Perhaps you could post a minimal snippet of compileable code to help others help you.
Well, I am using Visual C++, So its not that hard, but I know what I'm doing with the forms. Infact, I think I know how to input it into the rich text box.

Would it be possible for me to do X x 10, and make it so when ever that calculation is done, the answer is stored as X, and X's original value is 10?

And then count the amout of 0's in X and store it in Y?

I don't really know, as I said, just learning. Although strings sounded interesting.

Now, I don't think there is point in posting the code, because I havn't done much yet, just small things like when the button is pressed, text changes, ect (I can do that easy :p )
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Math Functions

 
0
  #4
Aug 12th, 2006
Here's a cheap and ugly, bargain-basement example of what I meant about using strings.
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main ( void )
  5. {
  6. char text[50] = {'3'}; /* a cheap way of having a starting value */
  7. int i;
  8. for ( i = 0; i < sizeof text - 1; ++i )
  9. {
  10. puts(text);
  11. strcat(text, "0");
  12. }
  13. return 0;
  14. }
  15.  
  16. /* my output
  17. 3
  18. 30
  19. 300
  20. 3000
  21. 30000
  22. 300000
  23. 3000000
  24. 30000000
  25. 300000000
  26. 3000000000
  27. 30000000000
  28. 300000000000
  29. 3000000000000
  30. 30000000000000
  31. 300000000000000
  32. 3000000000000000
  33. 30000000000000000
  34. 300000000000000000
  35. 3000000000000000000
  36. 30000000000000000000
  37. 300000000000000000000
  38. 3000000000000000000000
  39. 30000000000000000000000
  40. 300000000000000000000000
  41. 3000000000000000000000000
  42. 30000000000000000000000000
  43. 300000000000000000000000000
  44. 3000000000000000000000000000
  45. 30000000000000000000000000000
  46. 300000000000000000000000000000
  47. 3000000000000000000000000000000
  48. 30000000000000000000000000000000
  49. 300000000000000000000000000000000
  50. 3000000000000000000000000000000000
  51. 30000000000000000000000000000000000
  52. 300000000000000000000000000000000000
  53. 3000000000000000000000000000000000000
  54. 30000000000000000000000000000000000000
  55. 300000000000000000000000000000000000000
  56. 3000000000000000000000000000000000000000
  57. 30000000000000000000000000000000000000000
  58. 300000000000000000000000000000000000000000
  59. 3000000000000000000000000000000000000000000
  60. 30000000000000000000000000000000000000000000
  61. 300000000000000000000000000000000000000000000
  62. 3000000000000000000000000000000000000000000000
  63. 30000000000000000000000000000000000000000000000
  64. 300000000000000000000000000000000000000000000000
  65. 3000000000000000000000000000000000000000000000000
  66. */
[edit]For amusement, a small change.
#include <stdio.h>
#include <string.h>

char text[1000000] = {'3'}; /* a cheap way of having a starting value */

int main ( void )
{
   int i;
   for ( i = 0; i < sizeof text - 1; ++i )
   {
      puts(text);
      strcat(text, "0");
   }   
   return 0;
}
Last edited by Dave Sinkula; Aug 12th, 2006 at 1:43 am.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Re: Math Functions

 
0
  #5
Aug 12th, 2006
this->richTextBox1->Text = "CurrentNumber";
int CurrentNumber = 10;
CurrentNumber = CurrentNumber * 10;

Just a thought from a n00b, I know this doesn't work, it just makes the text CurrentNumber show up...However is there a way I could make that work? So it shows the variable?

This might not work...Seems simple though.


--------------------------------------------------------------------------------------------------

Edit:

How would I impliment what you showed me, to display in a text box? Is there a way I can control where the output goes?
Last edited by Wreef; Aug 12th, 2006 at 2:17 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Math Functions

 
0
  #6
Aug 12th, 2006
Well if you want to run the program in real time then you need to reconsider your idea since in the end you would end up seeing the final value in the text box (due to the fast execution of your program) or until you run out of buffer.

Maybe you need to implement a delay which would update the contents in the text box at regular intervals of time.

  1.  
  2. char text[1000000] = {'3'};
  3. for ( i = 0; i < sizeof text - 1; ++i )
  4. {
  5. this->richTextBox1->Text = text;
  6. strcat(text, "0");
  7. // some delay function
  8. }

This is what i think should come, but still i would like Dave to verify this for me coz this is just the logic i think should be used.

Hope it helped, bye.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Re: Math Functions

 
0
  #7
Aug 12th, 2006
I understand some of that code...But I always get errors when I try implimenting it.

I've made a big mess of my code, so I have started a new project, and I'm up to the same thing as I was before, I need to get the basics of this working.


In theory, would I be able to, somehow, store 10 in a variable, * by 10, override the variable with my new answer, then repeat. While at the same time my textbox is refreshing every second?


Also, another question, I seen things like "this->" leading to heaps of different things, what does this mean? I tried finding it on google, but there wasn't much help, I guess because the word "This" can be used for alot of things :p
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Re: Math Functions

 
0
  #8
Aug 13th, 2006
Well, I finaly got it working with 64bit int

  1. unsigned int X = 10;
  2. unsigned _int64 Y = 10;

Anyway, I need bigger, I found out the only way to do this would be strings, this will also be easier when I later go to put it in index form, as I can just count the string.

Problem, I don't know one thing about strings!

I am using Visual Studio, so C++ .net and I can't get anything to do with strings working.

string s; //Gives an error

s.append ("0") //Gives an error

Infact, anything to do with strings gives me errors, must be doing something wrong.

Can someone please help?

At the moment I'm using


  1. unsigned int X = 10;
  2. unsigned _int64 Y = 10


And

  1. if ( this->toolStripStatusLabel1->Text == "Running" ) {
  2. Y = X * Y;
  3. this->richTextBox1->Text = Convert::ToString(Y);

Like I said, it works, but no more than a 18 didget number...Need strings.

Can someone help me replace the int's with strings? Explain how?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: Math Functions

 
0
  #9
Aug 13th, 2006
@Wreef
Did you include <string>?
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 40
Reputation: Wreef is an unknown quantity at this point 
Solved Threads: 1
Wreef Wreef is offline Offline
Light Poster

Re: Math Functions

 
0
  #10
Aug 13th, 2006
Originally Posted by Grunt
@Wreef
Did you include <string>?
When ever I include string I get 100's of errors
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC