-2
我正在試圖創建一個程序,計算Vt給定的值Vt,a和tm。當我運行代碼時,程序首先詢問第一個問題,然後給它一個值,然後通過代碼加速,而不讓我給其他兩個變量賦值。我用C編程。這是代碼:我該如何修復我的代碼?我認爲這個問題是第一個scanf?
#include <stdio.h>
main() {
float Vt;
float Vo;
float a;
float tm;
printf(" At what time in flight do you wish to know the velocity? To the
nearest hundredth. :");
scanf(" %.2f", &tm);
printf (" What is the angle of trajectory? :");
scanf (" %.2f", &a);
printf (" What is the initial velocity? :");
scanf (" %.2f", &Vo);
float sina = sin (a);
float cosa = cos (a);
float tana = tan (a);
Vt = sqrt((pow((Vo * cosa), 2.0)) + (pow((Vo * sina - (9.8 *tm)), 2.0)));
printf("\n\n\n\n %.3f", Vt);
return 0;
}
https://stackoverflow.com/questions/1669821/scanf-skips-every-other-while-loop-in-c的可能的複製 –
你的主要是真的老了,你應該升級! –
嘗試使用'%f'而不是'%.2f' – BLUEPIXY