C

Asked • 06/03/19

Can someone please tell me if my code has anything wrong with it?

I have this project for school where I have to fund a formula and make a program to calculate it. I chose the control formal for bullet ballistics, which is X = (v² / g) * Sin(2 theta) , where X = maximum distance, v = muzzle velocity ,g = gravity (32 as constant) and Sin(2 Theta) = the sin value of twice the firing elevation angle ( if the gun is fired at an angle of 30 degrees, use the sine value of 60 degrees). I am getting weird values in the calculations. is it possible if someone can identify anything wrong with the code? Code: //Calculator for bullet ballistics #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #define g 32 #define PI 3.1416 void main(void) {  float X, v, vg, v2, elevation, elevationRad, e, Sin2Theta, Theta2, Theta, ThetaDeg, choice, restart, restart2;  restart = 0;  while (restart <= 1)  {   printf("Please state what you are trying to find.\\n");   printf("1. Maximum distance\\n");   printf("2. Muzzle velocity\\n");   printf("3. Elevation angle\\n");   scanf("%f", &choice);     if (choice == 1) //calculating maximum distance   {    printf("You are now calculating Maximum distance.\\n");    printf("Please enter the muzzle velocity (m/s): ");    scanf("%f", &v);    printf("Please enter the elevation angle (degree)");    scanf("%f", &elevation);    elevationRad = (180 / PI) * elevation;    Sin2Theta = sin(2 * elevationRad);    X = (pow(v, 2) / g) * Sin2Theta;    printf("The maximum distance is %f feet\\n", X);    printf("Would you like to restart? 1. Yes 2. No ");    scanf("%f", &restart2);    restart = restart + restart2;   }   else if (choice == 2) //calculating muzzle velocity   {    printf("You are now calculating Muzzle velocity.\\n");    printf("Please enter the maximum distance (feet): ");    scanf("%f", &X);    printf("Please enter the elevation angle (degree):");    scanf("%f", &elevation);    elevationRad = (180 / PI) * elevation;    Sin2Theta = sin(2 * elevationRad);    vg = X / Sin2Theta;    v2 = vg / g;    v = sqrt(v2);    printf("The muzzle velocity is %f m/s \\n", v);    printf("Would you like to restart? 1. Yes 2. No ");    scanf("%f", &restart2);    restart = restart + restart2;   }   else //calculating elevation angle   {    printf("You are now calculating Elevation angle.\\n");    printf("Please enter the maximum distance (feet): ");    scanf("%f", &X);    printf("Please enter the muzzle velocity (m/s):");    scanf("%f", &v);    Sin2Theta = X / (pow(v, 2) / g);    elevationRad = asin(Sin2Theta);    elevation = (elevationRad / 2);    e = (180 / PI)* elevation;    printf("The elevation angle is %f degrees \\n", e);    printf("Would you like to restart? 1. Yes 2. No ");    scanf("%f", &restart2);    restart = restart + restart2;   }  } }

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.