Pointer isn't usable in calculator

Viewed 54
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

#define PI 3.142

main(){

    float fn, sn, ans;

    printf("Hello, please enter your first number and second number: ");

    scanf("%f %f", &fn, &sn);

    ans = (fn**sn);

    printf("%f", ans);

}

The compiler complains that there is a pointer required in the line with ans = (fn**sn);.

What is the pointer required? I tried to put "" in the statement but the output is wrong number, not the power of fn and sn.

2 Answers

Unlike in Python, ** isn't a valid operator in C. The compiler is treating the first * as multiplication but then it thinks that the second * is dereferencing a pointer, which sn isn't.

If you're trying to perform multiplication, use a single *. If you're trying to perform exponentiation, use pow from math.h.

For example,

ans = pow(fn,sn);

What ans is supposed to be ?

ans is of type float.

fn and sn are of type float too.

You can not use the operator "*" on sn. You only can use it on pointers. But sn is not a pointer.

Related