Velocity app.

I have a code shown like this...
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
#include <iostream>
#include <conio.h>
#include <math.h>

#define pi 3.14159265

using namespace std;

int main()
{
    double vel, drg, a, vx, vy, v;
    cout << "Velocity? "; cin>>vel;
    cout<<"Angle? "; cin>>drg;
    a=(drg*pi)/180;
    vx=vel*sin(a);
    vy=vel*cos(a);
    cout<<"\n==========="<<endl;
    cout<<" Velocity "<<endl;
    cout<<"=========="<<endl;
    for(vy;vy>=0;vy-=9.8){
        v=sqrt(pow(vx,2)+pow(vy,2));
        cout<<"  "<<v<<endl;
    }
    for(vy;vy<=vel*cos(a);vy+=9.8){
        v=sqrt(pow(vx,2)+pow(vy,2));
        cout<<"  "<<v<<endl;
    }
    getch();
}

I want it to show like this:

Velocity? 33
Angle? 45

===========
Velocity
=========
33
26.9
23.6
23.6
26.9
33

but it show up 24.11 between 23.6. How to handle that? Thanks :-(

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
#include <iostream>
#include <conio.h>
#include <math.h>

#define pi 3.14159265

using namespace std;

int main()
{
    double vel, drg, a, vx, vy, v;
    cout << "Velocity? "; cin>>vel;
    cout<<"Angle? "; cin>>drg;
    a=(drg*pi)/180;
    vx=vel*sin(a);
    vy=vel*cos(a);
    cout<<"\n==========="<<endl;
    cout<<" Velocity "<<endl;
    cout<<"=========="<<endl;
    for(vy;vy>=0;vy-=9.8){
        v=sqrt(pow(vx,2)+pow(vy,2));
        cout<<"  "<<v<<endl;
        if(vy<9.8){break;}////////////////////////
    }
    for(vy;vy<=vel*cos(a);vy+=9.8){
        v=sqrt(pow(vx,2)+pow(vy,2));
        cout<<"  "<<v<<endl;
    }
    getch();
}
thanks vin! You really just make my night :-)!
Topic archived. No new replies allowed.