我有一个明天到期的家庭作业,希望我们提示用户输入汽车的数量、行驶里程,然后显示总成本。费用取决于里程数;如果低于 100,则为 25 美分/英里,如果超过 100,则成本为 100 + 15 美分/英里。我创建了一个包含Miles
和的结构Price
。这是我到目前为止所拥有的:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
struct Cars
{
int Miles;
double Price;
};
int main()
{
cout << "ENTER ALL OF THE CARS!";
int NoCars;
cin >> NoCars;
Cars* info = new Cars[NoCars];
int i;
for (i=0; i<NoCars; i++)
{
cout << "How many miles were driven on this car? :";
cin >> info[i].Miles;
if(Miles > 100)
{
Price = 25 + 0.15 * Miles;
}
else
{
Price = 0.25*Miles;
}
}
cout << "Here are the prices: \n";
for(x=0, x < NoCars; x++)
{
cout << info[x].Price;
}
return 0;
}
如您所见,我尝试Price
使用语句修改变量if
,但似乎无法简单地访问它。任何指针?