error: invalid operands of types `double' and `double' to binary `operator^'

I have a few errors here that I am trying to clear. I am using Dev-C++ to build this program. Obviously I am new to this.

The errors I am receiving;

main.cpp: In function `int main(int, char**)':
main.cpp:48: error: invalid operands of types `double' and `<unknown type>' to binary `operator*'
main.cpp:48: error: invalid operands of types `<unknown type>' and `int' to binary `operator^'
main.cpp:48: error: invalid operands of types `double' and `double' to binary `operator^'
make.exe: *** [main.o] Error 1

They all pretty much refer to the following;

int height = ((tangent*(angle)*distance))-((.5)*(g)*((distance^2)/((speed^2*(cos(angle)*(cos(angle)))))));


[u][i][b]Here is the rest of the program


#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{


cout << "This program will find the height that a basketball" << endl;
cout << "launched by a robot that is 10 meters from the backboard." << endl;
cout << "The user will enter the initial speed and firing angle." << endl;
cout << "The local acceleration of gravity is g = 9.81 m/s2." << endl;
cout<< endl;




//Instruct the user to enter variables
double speed;
double angle;
cout << "Please enter the initial speed in m/s: ";
cin >> speed;
cout << endl;
cout << "Please enter the initial angle in degrees: ";
cin >> angle;
cout << endl;


//Formulas for conversions
{
double PI = 3.14159265359;
double degree = PI / 180.0;
double tangent = (angle)*(degree);
double g = 9.81;
int height = ((tangent*(angle)*distance))-((.5)*(g)*((distance^2)/((speed^2*(cos(angle)*(cos(angle)))))));

//Display the results
cout << endl;
cout << setfill('*')<<setw(37)<<" "<<endl;
cout << right<<setw(11)<<" Output "<<setw(13)<<" "<<endl;
cout << setfill('*')<<setw(37)<<" "<<endl;
cout << setw(3)<<" "<<setfill(' ') << right << setw(19) << setprecision(2) << "Distance = ";
cout << right << setw(7) << fixed << showpoint << "10.00" <<setfill('*')<<setw(3)<<" "<<endl;
cout << setw(3)<<" "<<setfill(' ') << right << setw(19) << setprecision(2) << "Initial Speed = ";
cout << right << setw(7) << fixed << speed <<" "<<setw(3)<<setfill('*')<<" "<<endl;
cout << setw(3)<<" "<<setfill(' ') << right << setw(19) << setprecision(2) << "Initial Angle = ";
cout << right << setw(7) << fixed <<angle <<" "<<setfill('*')<<setw(3)<<" "<< endl;
cout << setw(3)<<" "<<setfill(' ') << right << setw(19) << setprecision(2) << "Height = ";
cout << right << setw(7) << fixed <<height<<" "<<setfill('*')<<setw(3)<<" "<< endl;
cout << setfill('*')<< setw(37)<<" "<<endl;
cout << setfill('*')<< setw(37)<<" "<<endl;
cout << endl;
cout << endl;
cout << "You have received height of a basketball launched by a robot, 10 meters"<<endl;//reiterate the reason for the program
cout << "from the backboard at your given speed and angle."<<endl;
cout << endl;
cout << endl;

system("PAUSE");
return EXIT_SUCCESS;
}}


First thing I would try is removing the ^ operator.

I'm guessing from your calculations that you're expecting it to be an exponent, it's not, it's a bitwise 'exclusive or' operator.

EDIT: Obviously, I don't mean completely remove it. I mean sub it for a simple * operator:

1
2
distance^2 // Change instances of this....
distance * distance // ... to this 
Last edited on
Yup I took that out and gave distance a value as it had not been defined and it worked. Thanks!
Topic archived. No new replies allowed.