Thread: Illegal exponent operator, how do i fix this?

  1. #1

    Illegal exponent operator, how do i fix this?

    run compiler w/o precompiled headers

    Bug: It says my exponent operator is incorrect, how do i fix this? Thanks

    #include <iostream>
    using namespace std;

    //Math functions
    #include <cmath>

    //Function prototype compute_range()
    double compute_range(double angle, double velocity);

    //Function prototype show_results()
    void show_results(double range);

    int main()

    //boolean condition set to false
    bool cont = false;

    //Intialized variables
    char answer = 'y';
    double angle, velocity, range;

    //do while loop

    cout << "Please input an angle in degrees: ";
    cin >> angle;
    cout << endl;
    cout << "Please input velocity in meters per second: ";
    cin >> velocity;
    cout << endl;

    range = compute_range(angle, velocity);


    cout << "Continue (y/n) ? ";
    cin >> answer;
    cont = (answer == 'y');

    //End while

    return 0;
    /************************************************** */
    //Function call computer_range()
    double compute_range(double angle, double velocity){

    double const GRAVITY = 9.8;
    double range;

    range = sin(2 * angle) * velocity^2 / GRAVITY;

    /************************************************** */

    //Function call show_results()
    void show_results(double range){

    cout << "The range is: " << range;


  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Plano, Texas, United States
    the ^ is not the exponent operator in C++. Use the pow() function. In this case, you would do: pow(velocity, 2). It is in math.h.

    If you wanted to make the ^ and exponent operator, you would have to overload it, like this:

    double operator ^ (double lhs, double rhs)
    return pow(lhs, rhs);

    THEN you could say velocity^2
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  3. exponent math, calculus?
    By phosphorousgobu in forum C++ Programming
    Replies: 11
    Last Post: 10-20-2004, 10:55 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Illegal Characters
    By Echidna in forum Windows Programming
    Replies: 3
    Last Post: 12-08-2002, 04:56 AM