简体   繁体   English

Visual Studio(C)-打印信息..我如何获得价值?

[英]Visual Studio ( C ) - Printing inf .. how do i get a value?

I'm doing a project for school and after doing calculations, the printed result is always ' inf '. 我正在做一个学校项目,计算后,打印结果始终是'inf'。 I've done a lot of research and i cannot figure out how to show the value calculated. 我已经做了很多研究,但我不知道如何显示计算出的值。

Program works likes this: 程序的工作原理如下:

The user enters the high and low warp factors and the increment value in a specific range. 用户在特定范围内输入高/低翘曲系数和增量值。 Then the program calculates the velocity from the low warp factor point to the high warp factor point and prints each result to the screen. 然后程序计算从低翘曲系数点到高翘曲系数点的速度,并将每个结果打印到屏幕上。

velocity calculation for old star trek is v=(w^3)*c velocity calculation for the new star trek is v=(w^(10/3))*c 旧星际迷航的速度计算为v =(w ^ 3)* c新星迷航的速度计算为v =(w ^(10/3))* c

v is velocity, w is warp factor and c is the speed of light. v是速度,w是翘曲因子,c是光速。 these calculations are provided from the school. 这些计算是由学校提供的。 the variable newV represents the new generation velocity calculation and always shows up as ' inf '.. i'm stuck here and don't know what to do. 变量newV表示新一代速度计算,并且始终显示为“ inf”。我被困在这里,不知道该怎么办。

Here's the code: 这是代码:

double oldV = 0.0;                          
double newV = 0.0;                      
const double c = 299792458.0;   

for (double i = low; i < high; i = i+increment)
{

    oldV = ((pow(low, 3))*c)*3.6;
    newV = pow(low, (10 / (float)3)*c)*3.6;
    low = low + increment;
    printf("%20.2f%20.2lf%20.2a\n", i, oldV, newV);

}//end of calculation for loop

I know it's a read but i had to explain, thanks in advance for helping! 我知道这是一本读物,但我必须解释一下,在此先感谢您的帮助!

You have the parentheses wrong on this line: 您在此行上的括号有误:

newV = pow(low, (10 / (float)3)*c)*3.6;

According to the formula given, c should be outside of the pow function: 根据给定的公式, c应该在pow函数之外:

newV = pow(low, (10 / (float)3))*c*3.6;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM