This is probably a really simple question, but is there a way in a program to have it calculate say the log of an inputted number and if so, how?
This is probably a really simple question, but is there a way in a program to have it calculate say the log of an inputted number and if so, how?
Create a dynamic array where you store the numbers that get input.
I don't know how to dynamically assert dimensions. So I can only give you an example when you get to know at runtime the number of inputs you will get...
Considering only integer numbers are allowed:
Another option, to avoid you the trouble of dynamically creating the array. Would be, of course to create some array with 1000 dimensions and hope the user gets bored after introducing seven hundred or so numbersCode:int* pnumbers = 0; //init pointer to array int max = 0; //init number of inputs cout << "How many numbers will you input?"; cin >> max; //and you now know the dimensions for the array if(!(pnumbers = new int[max])) //Create the array dynamically { cout << "Out of memory!"; exit(1); //if there is no memory left, abort } for(int i=0; i<max;i++) { cout << "Insert a number" << endl; cin >> *(pnumbers+i) //this adds to the array the number introduced } //... do something with the array delete [] pnumbers; //Free up the memory. IMPORTANT!! pbnumbers = NULL;
Regards,
Mario Figueiredo
Using Borland C++ Builder 5
Read the Tao of Programming
This advise was brought to you by the Comitee for a Service Packless World
Try log functions found in math.h
Code:double log( double x ); float logf( float x ); double log10( double x ); float log10f ( float x );
He! *smack me*
Regards,
Mario Figueiredo
Using Borland C++ Builder 5
Read the Tao of Programming
This advise was brought to you by the Comitee for a Service Packless World
The <cmath> header file contains a number of the more complex math functions that you may be looking for.
Specifically, log(x) and log10(x) are included in this group assuming you are looking for either the natural log (base e) or common log (base 10).
Simply pass the input number as an argument to the function:
Arguments and return values are, technically, double-precision floating-point numbers, though single-precision values are acceptable.Code:double x; double y; : : y = log(x);
You'll need to do some "homework" to see what the file has available and what functions are available to meet your needs.
(Mario,
Keep wrestling with your three-year-old! You need a break, my friend. No biting!! P.S. Re-read the question! )
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
Really, i'm going crazy here. Almost finishing what the writter calls C++ basics. Hah! funny guy. Right now i'm dealing with polymorphism and inheritance and some more crazy pointers...
I'm telling you; If I get past this with my mind still in place, it will for sure attack some other part of my body. Wonder if C++ programmers invented viagra...
Regards,
Mario Figueiredo
Using Borland C++ Builder 5
Read the Tao of Programming
This advise was brought to you by the Comitee for a Service Packless World
Viagra doesn't work on C++ programmers, Mario. We keep thinking that we've found an important solution rather than recognizing what's really going on!
(Occupational hazard.)
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow