help with log project

this is what it is suppose to be


Your program will prompt for a positive number to find the logarithm of. Finally, your program will output the logarithm base b of the number n. The main function will be responsible for getting the input from the user, outputting your name and description of the program, and computing the resulting logarithm.
For this project you must use a function from the cmath library. Specifically, when you implement the change of base formula you will want to use either the log (loge) or log10 (log10) function.
Your output should look exactly like the example below. The example below is for a base of 2 and a number 32
1
Please enter the base (must be greater than 0): 2
Please enter a number (must be greater than 0): 32
The logarithm base 2 of 32 is 5.


heres my code


to me
/*
* File: main.cpp
* Author: Zac
*
* Created on September 22, 2015, 10:04 AM
*/

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


int main() {
int num1 = 2;
int num2 = 32;


cout << "Please enter the base (must be greater than 0)" << endl;
cin >> num1;
cout << "Please enter a number (must be greater than 0)" << endl;
cin >> num2;
cout << "The logarithm base 2 of 32 is :5";





Ok so just use a change of base formula:

log(base n) of X = ( log(base10) of X ) / ( log(base10) of N)
do i include it in the last line
First of all, don't initialize your num1 and num2 to anything because you're going to be replacing it with numbers that you put in.

And yes, you will put it in the last line, the line RIGHT before you output your results.
here is the update


Zachary Penna/*
* File: main.cpp
* Author: Zac
*
* Created on September 22, 2015, 10:04 AM
*/

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


int main() {
double base;
double num;


cout << "Please enter the base (must be greater than 0)" << endl;
cin >> base;
cout << "Please enter a number (must be greater than 0)" << endl;
cin >> num;







Ok...I don't see any significant updates other than a change in variable types...

Also rule of thumb: if you're not gonna call any methods in a specific library, don't #include them. I'm not seeing anything from iomanip and I highly doubt you're going to be needing methods within the cstdlib library.

The only things you'll actually need are iostream, std, and cmath.

And try to implement the change in base formula.
http://www.mathwords.com/c/change_of_base_formula.htm
http://www.cplusplus.com/reference/cmath/
would i use input or output the equation
/*
* File: main.cpp
* Author: Zac
*
* Created on September 22, 2015, 10:04 AM
*/

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


int main() {
double base;
double num;


cout << "Please enter the base (must be greater than 0)" << endl;
cin >> base;
cout << "Please enter a number (must be greater than 0)" << endl;
cin >> num;
cout << log(base n) of X = ( log(base10) of X ) / ( log(base10) of N)


return 0;
}
/*
* File: main.cpp
* Author: Zac
*
* Created on September 22, 2015, 10:04 AM
*/

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


int main() {
double base;
double num;


cout << "Please enter the base (must be greater than 0)" << endl;
cin >> base;
cout << "Please enter a number (must be greater than 0)" << endl;
cin >> num;
cin >> log(base n) of X = ( log(base10) of X ) / ( log(base10) of N);

return 0;
}
Alright. I highly doubt you read into any of the links I gave you. What I posted was not code; it was a formula for you to use as a reference when you're writing the code...

And triple posting in the same forum in the same section is not at all helping your case.
http://www.cplusplus.com/forum/beginner/174263/
http://www.cplusplus.com/forum/beginner/174266/

Protip: you do not want to use this forum as a do-your-homework tool. Because it ain't gonna happen.
Last edited on
You almost have it. Now just convert the formula into working code. As the assignment says, the log10() function will be helpful here.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
cout << "Please enter the base (must be greater than 0)" << endl;
cin >> base;
cout << base << endl;

cout << "Please enter a number (must be greater than 0)" << endl;
cin >> num;
cout << num << endl;

cout << "log(base 10) of base is: " << log(base) << endl;
cout << "log(base 10) of  num is: " << log(num) << endl;

//cin >> log(base n) of X = ( log(base10) of X ) / ( log(base10) of N); 
Topic archived. No new replies allowed.