1. Ваша функция подписи принимает 3 аргумента, и вы только поставить 1. Как он компилирует, я не знаю, как я не думаю, что это должно быть.
2. Функция CalculateAirTime
печатает переменную перед ее вычислением. Сначала это сделать: printf("Total air time: %f\n", time);
, а затем рассчитать фактическое эфирное время: time = ((2*velocity)*sin(angle)/GRAVITY);
3. Как совет, так как функция CalculateAirTime
нужна скорость и угол, чтобы вернуть расчетное время, не провести время в качестве параметра. Это бесполезно. Вы можете объявить двойную переменную внутри функции или напрямую вернуть расчетное время.
Заменить double CalculateAirTime(double velocity, double angle, double time){...}
с double CalculateAirTime(double velocity, double angle){...}
* EDIT! Для ясности, вот как я бы, наверное, написать программу: **
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
#define GRAVITY 9.8
/*
I renamed some variables. Just from the variable names, I think you do not understand the solution
for this "air time" problem well. I might be mistaken tough. If you have any questions, please
ask them. You are not leaving this place until you fully understand what is happening.
*/
// Function DECLARATION:
double CalculateAirTime(double Initial_Velocity, double Launch_Angle);
int main(void)
{
// variables
double Initial_Velocity;
double Launch_Angle;
// Initial_Velocity = 20.0 should work aswell. This is called a cast. You will learn about it later
Initial_Velocity = (double)(20.0);
// Converting 45 degrees to radians, because the sin() library function works with radians
Launch_Angle = (double)((45.0/180.0)*PI);
//Call function using our declared values as input
CalculateAirTime(Initial_Velocity,Launch_Angle);
return 0;
}
// Function DEFINITION
//Try to use the same name for paramaters here, as you did in the declaration!
double CalculateAirTime(double Initial_Velocity, double Launch_Angle)
{
double Air_Time;
Air_Time = (double)((2*Initial_Velocity)*sin(Launch_Angle)/GRAVITY);
printf("Total air time: %f\n", Air_Time));
return time;
}
Ваша функция имеет 3 аргумента, но вы только поставить один? – Li357
Имейте в виду, что 'sin()' принимает аргумент в радианах вместо градусов. – timrau
В чем вопрос? –