math question for my program

I am about to start a program that requires using a formula that calculates the distance of a launched projectile given the velocity and angle. The formula is:

distance = ((velocity*velocity)*sin(2*angle))/32.2

Can anyone explain what 'sin' is so i can start writing my program?
Thanks. I still dont understand it, but i did find the sin() function in the cmath header so it should work.
Just make sure you use radians instead of degrees on the angle :)
I compiled the program but i don't think its working. I am not very good at math, so i cant check by hand by calculating the formula. Its supposed to be a game where the user inputs an inital distance, then starts inputting velocities and angles trying to get within 1% of the target. The results seem to be all over the place. Did i miscalculate something?

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <cmath>

using namespace std;

float calcDistance(float, float);
void getInput(float&, float&);
const float pi = 3.14159265;

int main()
{
    float userDistance, velocity, angle, actualDistance;
    int tries = 0;
    bool check = 1;
    
    cout << "Enter distance of the target: ";
    cin >> userDistance;
    cout << endl << "Enter velocity of projectile: ";
    cin >> velocity;
    cout << endl << "Enter angle of projectile: ";
    cin >> angle;
    cout << endl << endl;
    
    while(check)
    {
                actualDistance = calcDistance(velocity, angle);
                
                   if(userDistance <= actualDistance)
                   {
                                   if(abs(actualDistance - userDistance) <= actualDistance * .01)
                                   {
                                   cout << "hooray, you win!";
                                   check = 0;
                                   }
                   else            
                                   {   
                                   cout << "Your projectile missed by " << actualDistance - userDistance << endl << endl;
                                   getInput(velocity, angle);
                                   tries++;
                                   }
                                   }
                   if(userDistance >= actualDistance)
                   {
                       if(abs(userDistance - actualDistance) <= actualDistance * .01)
                       {
                                   cout << "hooray, you win!";
                                   check = 0;
                                   }
                       else
                       {
                       cout << "Your projectile missed by " << userDistance - actualDistance << endl << endl;
                       getInput(velocity, angle);
                       tries++;
                       }
                       }
                       
               if(tries == 5)
               {
                        cout << "You are out of tries." << endl;
                        check = 0;
                        }         
                        }
                        
               system("pause");
               return 0;
               
               }
               
//****************************************************************************
// value return to actualDistance

float calcDistance(float velocity, float angle)
{
      // converting angle to radians
      float radians, convertDistance;
      
      radians = (angle * pi)/180.0;
      
      convertDistance = ((velocity*velocity)*sin(2*radians))/32.2;
      
      return convertDistance;
      
      }
      
//*****************************************************************************
// void function to prompt for input

void getInput(float& velocity, float& angle)  
{
     cout << "Input new velocity: ";
     cin >> velocity;
     cout << endl << "Input new angle: ";
     cin >> angle;
     cout << endl << endl;
     
     }                               
                              
          
Last edited on
Topic archived. No new replies allowed.