Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having an issue getting my decimals to 3 decimal places. Also my code isn't outputting like the picture below. I need it as close

I'm having an issue getting my decimals to 3 decimal places. Also my code isn't outputting like the picture below. I need it as close as possible to that. Please help! Thanks!
Code is below:
#include
#include
#include
#define PI 3.14159265
void updatePosition (double pos[],double vel[]);
void updateVelocity (double vel[],const double acc[],const double timeInc);
void outputPosition(double pos[]);
const double timeInc = 0.001;
const double initialVelocity = 110;
const double acc[3] = {0,0.25,-9.81};
int main()
{
double pos[3],vel[3];
double elevation = 62.900;
double azimuth = 2.9;
double val = PI / 180.0;
pos[0] =0;
pos[1] =0;
pos[2] =0;
double vel_g = initialVelocity * cos(elevation * val);
double vel_a = initialVelocity * sin(elevation * val);
vel[0] = vel_g * cos(azimuth * val);
vel[1] = vel_g * sin(azimuth * val);
vel[2] = vel_a;
double time =0;
do
{
updatePosition(pos,vel);
updateVelocity(vel,acc,timeInc);
printf("Time: %0.31f s", time);
outputPosition(pos);
time += timeInc;
}
while(pos[2] >0);
double diff_x=1000 - pos[0];
double diff = diff_x* diff_x;
double distance = sqrt(diff);
printf("Missed by %03.1f m ",distance);
printf("Author: Dalton Farrington ");
printf("Azimuth: %03.1f ",azimuth);
printf("Elevation angle: %03.1f ", elevation);
return 0;
}
void updatePosition(double pos[],double vel[])
{
pos[0] = vel[0]*timeInc + pos[0];
pos[1] = vel[1]*timeInc + pos[1];
pos[2] = vel[2]*timeInc + pos[2];
}
void updateVelocity(double vel[],const double acc[],const double timeInc)
{
vel[0] = vel[0] + acc[0] * timeInc;
vel[1] = vel[1] + acc[1] * timeInc;
vel[2] = vel[2] + acc[2] * timeInc;
}
void outputPosition(double pos[])
{
printf("X-Pos: %0.31f m", pos[0]);
printf("Y-Pos: %0.31f m", pos[1]);
printf("Height: %03.1f m ",pos[2]);
}
image text in transcribed
Output: Required Screen 998.613a V Pos 0.815m Height: 0.881 Tine 19,954s X-Pos: Time: 19,955s X-Pos: 998.663a V-Pos: -0.812 Height: 0.783 Time: 19,956s X-Pos 998, 713a V-Pos: 0.810m Height: 0.685 Time: 19,957s X-Pos 998, 763a Pos 0.80 Height: 0.587 rise 19.9586 X-Pos: 998,813a V-Pos: 0.805 Height: 0.489 rise: 19,959s X-Poo 998,863a V Pos 0.803 n Height: 0.391 riset 19, 9600 X-Pog 998,914a V-Post 0.800 n Height 0.293 rine: 19,9G1s X-Pos: 998, 964a V-Pos: 0.798n Height: 0.196 ine 19.9626 X-Pos 999,014n V-Pos: 0.795m Height: 0.098 ine 19,963s X-Pos 999,064n V-Pos 0.793 n Height 0.000 issed by 1.227 uthor: Dr. Gray zimuth -2.900 Elevation angle 62.900

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago