循环不工作 [英] Loop Not Working

查看:83
本文介绍了循环不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好。我有一个学校计划,可以预测一个弹丸撞到地面所需的秒数。我有公式,但循环没有发布到我的输出文件。有人能告诉我我做错了吗?

展开 | 选择 | Wrap | 行号

解决方案

In你的公式,你使用1/2。这对现实生活很好,但不适用于C ++ - 当一个整数除以另一个整数时,计算机返回一个整数,如果实际答案是小数,它会截断小数部分。因此1/2是0.5,它被截断为0,因此从不考虑由于重力引起的加速度,只考虑初始速度。尝试1.0 / 2.0而不是1/2。


程序正在发生一些奇怪的事情。它编译,但是当我打开提示并输入一个速度然后点击输入它只是跳到下一行并且什么都不做?我不知道发生了什么。


检查launch.dat的内容,看看你的输出是否正在写入。如果没有,该文件可能无法打开。


Hey Everyone. I have a program for school that is suppose to project how many seconds it takes a projectile to hit the ground. I have the formula, but the loop is not posting to my output file. Can someone tell me what I''m doing wrong?

Expand|Select|Wrap|Line Numbers

解决方案

In your formula, you use 1/2. That''s fine for real life, but not in C++ - When an integer is divided by another integer, the computer returns an integer, and if the actual answer is a decimal, it truncates the decimal part. So 1/2 is 0.5, which gets truncated down to 0, so the acceleration due to gravity is never considered, only initial velocity. Try 1.0/2.0 instead of 1/2.


Something weird is going on with the program. It compiles, but when I open the prompt and enter a velocity then hit enter it just skips to the next line and doesn''t do anything? I have no clue what''s going on.


Check the contents of launch.dat and see if your output is being written. If not, the file may not be opening.


这篇关于循环不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆