简体   繁体   English

有人可以告诉我我的代码有什么问题吗?

[英]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). 我为子弹弹道选择了控制形式,即X =(v²/ g)* Sin(2 theta),其中X =最大距离,v =炮口速度,g =重力(32为常数)和Sin(2 Theta) =两倍于射击仰角的正弦值(如果以30度角射击,则使用60度正弦值)。 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;
    }
}

}

I think instead of 我认为不是

   elevationRad = (180 / PI) * elevation;

it should be 它应该是

   elevationRad = (PI / 180) * elevation;

since, angle(in radians) = PI*angle(in degree)/180 因为, angle(in radians) = PI*angle(in degree)/180

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我我的代码有什么问题吗? - Can someone tell me what is wrong with my code? 有人可以告诉我以下汇编代码有什么问题吗? 获取分段错误 - Can someone please tell me whats wrong with the following Assembl code. Getting Segmentation fault 有人可以告诉我我的mergesort怎么了吗? - Can someone tell me what's wrong with my mergesort? 有人请告诉我为什么我的代码给了我错误的答案。程序应该接受一个整数输入并给出相应的阶乘。我 - Someone please tell me why my code gives me wrong answers.The program is supposed to accept an integer input and give the corresponding factorial.I 你能告诉我这怎么了吗 - can you please tell me whats wrong with this 有人可以帮我解释一下我的 c 代码有什么问题吗? - Can someone help me to explain what is wrong in my c code? 有人可以告诉我我的错误在哪里吗? 我的程序输出错误 - Can someone tell me where's my mistake? My program gives the wrong output 我的程序在 switch case 4 中不断地循环。有人可以看看并告诉我我做错了什么吗? - My program continuously goes through a loop in switch case 4. Could someone please take a look and tell me what im doing wrong? 有人可以使用fork()系统调用告诉我我的程序怎么了(编程C) - can someone tell me what's wrong with my program using fork() system calls(Programming C) 我似乎无法在树中插入节点。 有人可以看看我的代码并告诉我我哪里做错了吗? - I can't seem to insert a node in a tree. Can someone take a look at my code and tell me where did I do wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM