gpt4 book ai didi

c++ - 程序只读取第一行! C++

转载 作者:太空狗 更新时间:2023-10-29 21:25:48 26 4
gpt4 key购买 nike

<分区>

我的程序应该使用 .txt 文件作为输入(时间从 1 秒到 10 秒)来计算坠落物体的距离。文本文件内容如下:

12个3个4个5个6个78个910

这是我到目前为止的代码。

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;

//function prototype
double fallingDistance (int);

void main()
{
ifstream inputFile;
int time;
double distance;

//open the file
inputFile.open("05.txt");
inputFile >> time;

{
distance = fallingDistance (time);
cout << time << "\t\t" << distance << endl;
}
}
double fallingDistance (int time)
{
double distance, gravity=9.8;
distance = static_cast<double>(0.5 * gravity * pow(time,2));
return distance;
}

这是我的程序编译的内容:

1 4.9 press any key to continue...

提前致谢!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com