我对我的C++作业有问题。C++字符串和数组
编写一个程序来分析过去10天的汽油价格。首先,要求用户输入价格。然后执行以下操作: (a)计算并显示前5天的平均价格和第5天的平均价格 (b)比较两个平均价格。确定并报告哪一个更高(或者它们是相同的)。 (c)将每天的价格(第一天除外)与前一天的价格进行比较。确定它是否变得更高,更低或保持不变。计数并报告价格高于,低于和等于前一天价格的天数。
我不知道如何比较如何前五天与过去五天进行比较,C部分我完全靠....
失去我不会找人为我做我的作业,但是朝着正确的方向努力将是一个很大的帮助!
这里是我到目前为止做出:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double gasPrice[10];
double firstFive = 0.0;
double lastFive = 0.0;
double ffAvg = 0.0;
double lfAvg = 0.0;
for (int x = 0; x < 10; x = x + 1)
{
gasPrice[x] = 0.0;
}
cout << "You will be asked to enter daily gas prices for 10 days."<< endl;
ofstream gasprice;
gasprice.open("gasprice.txt", ios::app);
if (gasprice.is_open())
{
for (int x = 0; x < 10; x = x + 1)
{
cout << "Enter the gas price " << x+1 << ": ";
getline(cin, gasPrice[x];
}
if (ffAvg > lfAvg)
{
cout << "The first five days have a lower gas price " << ffAvg << lfAvg << endl;
}
else if (ffAvg < lfAvg)
{
cout << "The last five days have a lower gas price " << ffAvg << lfAvg << endl;
}
system("pause ");
return 0;
}
家庭作业需要被标记为SO上的家庭作业。我为你重新标记了它。 – Paulpro
@PaulPRO:不,它确实没有,它确实不应该。与家庭作业有关的一个好问题应该与一个与作业无关的好问题区分开来。 –
@James McNellis,重要的是人们知道他们在帮助家庭作业问题,所以他们可以帮助而不是仅仅给出最终答案。 – Paulpro