明日が期限の宿題があり、ユーザーに車の台数と走行距離を入力してもらい、総費用を表示させます。費用はマイル数によって異なります。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
ましたが、簡単にはアクセスできないようです。ポインタはありますか?