Xebiq
Xebiq

Reputation: 3

Logarithm calculator

I'm trying to make a logarithm calculator and got stuck—it doesn't print out a value. The problem may be at lines 15 or 24 or both. How can I make it print the value (all written in C).

Here's the full code:

#include <stdio.h>
#include <stdlib.h>

// Finds base 10 logarithms

int main()
{
    float result;
    float base = 10.0;
    float multiplier = 1.0;
    // float counter1 = 0.0;
    // float counter2 = 0;

    printf("Input result: ");
    scanf("%l", result);

    // Solves for all results above the base
    if(result > base) {
        while(result > multiplier) {
            multiplier =  multiplier * multiplier; // the multiplier has to check non-whole numbers
            multiplier += 0.001;
        } // division
    }
    printf("Your exponent is: %l \n", &multiplier);
    printf("Hello mathematics!");
    return 0;
}

All help appreciated, Xebiq

Upvotes: 0

Views: 181

Answers (2)

hanie
hanie

Reputation: 1885

you should delete & in printf,and add & in scanf.

printf("Your exponent is: %f \n", multiplier);
scanf("%f", &result);

and use %f in them.

and with base 10 I suggest this function to calculate log:

unsigned int Log2n(unsigned int n)
{
    return (n > 1) ? 1 + Log2n(n / 10) : 0;
}

also you should know about Floating-point numbers here: multiplier += 0.001;

probably exactly 0.001 won't be added to multiplier when I debugged this 0.00100005 was being add to multiplier in my compiler.(which will affect multiplying)

Upvotes: 1

sattva_venu
sattva_venu

Reputation: 715

In printf remove '&' and in scanf add '&' before variable.

Upvotes: 0

Related Questions