Compiling Error: why expected primary expression before "Float"

HI: I am trying to access a variable from a different function to calculate height. There were no errors using xrandomAngle, however, there is a compiling error to use Voy, calculating height.

Call of Overloaded'pow(int&, int)' is ambiguous* is the error

Here is a part of my program that is having compiling errors.
Also, 2nd question: If I wanted to access correctAns in the main class to increment the number of correct answers, every time the user inputs the correct amount, what do I have to do to change that? Atm, it is a public static variable in Class Rocket (I got a compiling error from trying to access this variable in main class)--> its undeclared in main-how do i get it to be same in main and rocket class?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Rocket
{
   private:
    int Voy; 
    int xrandomAngle;
    static const int GRAV= -10, Voi = 100;
        
  public:
     Rocket();
     int randomAngle();
     void tutorial();
     int calculateVoy();  
     int calculateHeight();  
     int rightRocket();
     static int correctAns;
};

//set correct answers back to zero
Rocket::Rocket()
{
  correctAns == 0;
}

//for every correct answer, keeps track of number of correct answers
int Rocket::rightRocket()
{
     return correctAns++;
}

int Rocket::randomAngle() 
{
    srand((unsigned)time(0)); 
    
    // produces a random height with range 25-80
    xrandomAngle = rand()%80+25;
    return xrandomAngle;
}

int Rocket::calculateVoy()
{
  Voy=Voi * (int)sin(xrandomAngle);
  return Voy;
}

int Rocket::calculateHeight()
{
  int height;
  height = (-pow(Voy,2))/(2*GRAV);
  return height;
}



Thanks

ERROR UPDATED BELOW
Last edited on
What is the actual error you are getting? And format your code, please.

The reason you can't adjust that static variable is because it's private.
fixed

was formated
tried to reformat a lil diff
but no change when sumbited

and it's static public the "correctAns"

xD
Last edited on
Use the format options on the right side of the text input box. The <> is for source code.
formated, but I it correctAns .. thought you could access it in main class if you make it static public >_<

Been tinkering with code some more and edited it
thought about in main:
(rest of code edited out for simplicity)

int correctAns;
then
1
2
Rocket q1; //object 
correctAns = q1.rightRocket();

...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>

using namespace std;

class Rocket
{
  private:
    int Voy; 
    int xrandomAngle;
    static const int GRAV= -10, Voi = 100;
        
  public:
     Rocket();
     int randomAngle();
     void tutorial();
     int calculateVoy();  
     int calculateHeight();  
     int rightRocket();
     static int correctAns;
};

//set correct answers back to zero
Rocket::Rocket()
{
  correctAns == 0;
}

//for every correct answer, keeps track of number of correct answers
int Rocket::rightRocket()
{
     return correctAns++;
}

int Rocket::randomAngle() 
{
    srand((unsigned)time(0)); 
    
    // produces a random angle with range 25-80 degrees
    xrandomAngle = rand()%80+25;
    return xrandomAngle;
}

int Rocket::calculateVoy()
{
  randomAngle();
  Voy=Voi * (int)sin(xrandomAngle);
  return Voy;
}

int Rocket::calculateHeight()
{
  calculateVoy();
  int height;
  
  float h = (-pow(float Voy,2))/(2*GRAV);  <-- NEW ERROR
  height = (int) h;
  return height;
}


ERROR: expected primary expression before "Float"
Last edited on
What is float Voy in your function call?!
As Vlad implies, I expect you meant

float h = (-pow((float)Voy,2))/(2*GRAV);
ah >_< ;; that was the error ty.
Hm another error popped up, but I just simplified the program to make it have no errors =x

ty so much for pointing out that mistake!
Topic archived. No new replies allowed.