0

Whenever I run the code my lines 52 and 61 keep giving me the same error message.

#include<stdio.h>
#include<math.h>

double getinput(void);
double calcwindchillold(double v, double t);
double calcwindchillnew(double v, double t);
void printResults(double windchillold, double windchillnew);

int main(void)
{
    double v = 0;
    double t = 0;
    double windchillold = 0;
    double windchillnew = 0;

    v = getinput();
    t = getinput();
    windchillold = calcwindchillold(v,t);
    windchillnew = calcwindchillnew(v,t);
    return 0;
}
double getinput(void)
{
    double v,t;
    printf("Input the wind speed in MPH: ");
    scanf("%lf", &v);
    printf("Input the temperature in degrees Fahrenheit: ");
    scanf("%lf", &t);


    return v,t;

}

double calcwindchillold(double v, double t)
{
    double windchillold;

    windchillold = ((0.3 * v^0.5) + 0.474 - (0.02 * v) * (t - 91.4) + 91.4);
// in the line above this is the error.

    return windchillold;
}

double calcwindchillnew(double v, double t)
{
    double windchillnew;

    windchillnew = 35.74 + 0.6215*t - 35.75*(v^0.16) + 0.4275 * t * v^0.16;
// in the line above this is the second error.

    return windchillnew;
}

void printResults(double windchillold, double windchillnew)
{
    printf("The wind chill using the old formula is: %lf F\n", windchillold);
    printf("The wind chill using the new formula is: %lf F\n", windchillnew);
}

This has the debug system say: error: invalid operands to binary ^ (have 'double' and 'double')

looked at other scripts that were also getting the 'double' errors and couldn't use that information to help my own.

I know its probably some simple thing that I looked over.

user2055813
  • 19
  • 1
  • 1
  • 1
    you can't apply `XOR` operation on `float` or `double`. – sgarizvi Feb 08 '13 at 21:09
  • 1
    Possible duplicate of [Why is my power operator (^) not working?](http://stackoverflow.com/questions/4843304/why-is-my-power-operator-not-working) – phuclv Nov 07 '15 at 03:34

4 Answers4

2

In C ^ is the eXclusive OR operator (XOR), not an exponentiation operator. You cannot XOR two floating-point values.

To exponentiate, you can use the pow(3) function from math.h.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
1

Bitwise operators don't work with operands of floating point type. The operands are required to have integer types.

(C99, 6.5.11p2 Bitwise exclusive OR operator) "Each of the operands shall have integer type."

^ is the bitwise exclusive or operator in C.

To use power operation, use the pow and powf functions declared in math.h.

ouah
  • 142,963
  • 15
  • 272
  • 331
1
#include <math.h>
double pow( double base, double exp );

In C you cannot return multiple values, so please do a single function like this ...

double getinput(const char* message) {
    double retval;
    printf("%s: ", message);
    scanf("%lf", &retval);
    return retval;
}

Before learning about pointers and how you can master the OS, try to keep your code as simple as possible.

Hope it helps :)

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
0

Another issue:

return v,t;

You can't have multiple return values in C.

You can either do this as out parameters on the call, or make separate functions. Eg:

void getinput(double* v_out, double* t_out)
PQuinn
  • 992
  • 6
  • 11