차 유형, 임대 일 및 마일 수에 대한 사용자 입력을 받아서 상수 값에 대한 변수를 계산하고 보고서를 생성하는 C++ 프로그램을 작성하고 있습니다. 필자는 사용자가 입력 한 carType, "f"또는 "c"를보고 해당 입력에서 계산을 수행하는 if 문을 사용하여 코드를 작성했습니다. 그러나 출력에는 차량의 이름이 표시되어야합니다. 입력 한 "f"또는 "c"가 아닌 ford 또는 chevrolet입니다.문자열 변수를 호출하는 중 오류가 발생했습니다.
편지를 가져 와서 브랜드와 동일시하는 동안 오류가 발생합니다. 또한 사용자가 만든 각 항목에 대한 헤더를 가져 오는 중, 5 개의 항목을 하나의 제목 아래에 가져 와서 출력 할 수 있습니까? 사전에
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
// Change the console's background color.
system ("color F0");
// Declare the variables.
char carType, brand;
string f("Ford"), c("Chevrolet");
int counter = 0, cars = 0;
double days, miles, cost_Day, cost_Miles, day_Total;
cout << "Enter the number of cars you wish to enter: ";
cin >> cars;
cin.ignore();
while (counter <= cars)
{
cout << "Enter the car type (F or C): ";
cin >> carType;
cin.ignore();
cout << "Enter the number of days rented: ";
cin >> days;
cin.ignore();
cout << "Enter the number of miles driven: ";
cin >> miles;
cin.ignore();
if (carType == 'F' || carType == 'f')
{
cost_Day = days * 40;
cost_Miles = miles * .35;
day_Total = cost_Miles + cost_Day;
brand = f;
}
else
{
cost_Day = days * 35;
cost_Miles = miles * .29;
day_Total = cost_Miles + cost_Day;
brand = c;
}
cout << "\nCar Days Miles Rental Cost\n";
cout << left << setw(13) << brand << left << setw(13) << days << left << setw(13) << miles
<< fixed << setprecision(2) << showpoint << "$" << setw(13) << right << day_Total << "\n\n";
counter++;
}
system ("pause");
}
감사 :
여기 내 코드입니다!
'brand'는'char'이지만'f'는'string'입니다. 작은 것을 큰 것으로 할당 할 수는 없습니다. –
보고 된 오류가 정확히 무엇인지, 컴파일러, 링커 또는 런타임 오류인지 여부를 나타내는 것이 좋습니다. –