我正在完成关于简单C ++程序的大学任务。到目前为止,我已经满足了大部分问题要求,但目前我仍然坚持未声明的标识符错误。提到的错误可以在代码的注释部分找到,其中注释包括术语“有问题的部分”。我的问题是,如何解决未声明的标识符错误?
如果您可以尝试编译源代码并查明问题,我将不胜感激。
构建错误:
1>c:\users\adrian khor\documents\visual studio 2013\projects\ict1101_as1_4\ict1101_as1_4\ict1101_as1_4.cpp(74): error C2065: 'feeReportTotalAfterDiscountedFee' : undeclared identifier
(MS Visual Studio Pro 2013)
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int qtyVehicleCar, qtyVehicleTaxi, qtyVehicleTruck;
/* Text UI component */
cout << "=====================================\n";
cout << "=====================================\n";
cout << "====== Malaysia Highway Company =====\n";
cout << "=====================================\n";
cout << "=====================================\n";
cout << endl;
cout << "Enter quantity of the vehicles on 1st January 2014: " << endl;
cout << "Car\t\t:\t";
cin >> qtyVehicleCar;
cout << "Taxi\t\t:\t";
cin >> qtyVehicleTaxi;
cout << "Truck\t\t:\t";
cin >> qtyVehicleTruck;
/* Lay out the Report table */
cout << endl << endl << endl;
cout << "Report\n";
cout << "--------\n";
cout << endl;
/* Processes */
/* ============ */
/* Declaration */
/* ============ */
// Report Items
double feeOriginalCar, feeOriginalTaxi, feeOriginalTruck;
feeOriginalCar = 2.00;
feeOriginalTaxi = 1.00;
feeOriginalTruck = 3.50;
double feeTotalOriginalCar, feeTotalOriginalTaxi, feeTotalOriginalTruck;
feeTotalOriginalCar = qtyVehicleCar * feeOriginalCar;
feeTotalOriginalTaxi = qtyVehicleTaxi * feeOriginalTaxi;
feeTotalOriginalTruck = qtyVehicleTruck * feeOriginalTruck;
double rateDiscountCar, rateDiscountTaxi, rateDiscountTruck;
rateDiscountCar = 2;
rateDiscountTaxi = 10;
rateDiscountTruck = 15;
double feeTotalDiscountedCar, feeTotalDiscountedTaxi, feeTotalDiscountedTruck;
feeTotalDiscountedCar = (rateDiscountCar / 100) * feeTotalOriginalCar;
feeTotalDiscountedTaxi = (rateDiscountTaxi / 100) * feeTotalOriginalTaxi;
feeTotalDiscountedTruck = (rateDiscountTruck / 100) * feeTotalOriginalTruck;
double feeTotalAfterDiscountedCar, feeTotalAfterDiscountedTaxi, feeTotalAfterDiscountedTruck;
feeTotalAfterDiscountedCar = feeTotalOriginalCar - feeTotalDiscountedCar;
feeTotalAfterDiscountedTaxi = feeTotalOriginalTaxi - feeTotalDiscountedTaxi;
feeTotalAfterDiscountedTruck = feeTotalOriginalTruck - feeTotalDiscountedTruck;
// Final Output
double feeReportTotalOriginalFee, feeReportTotalDiscountedFee, feeReportTotalAfterDiscounted;
feeReportTotalOriginalFee = feeTotalOriginalCar + feeTotalOriginalTaxi + feeTotalOriginalTruck;
feeReportTotalDiscountedFee = feeTotalDiscountedCar + feeTotalDiscountedTaxi + feeTotalDiscountedTruck;
/* The problematic part #2*/
/* feeReportTotalAfterDiscountedFee = feeReportTotalOriginalFee - feeReportTotalAfterDiscountedFee; */ /* OR */
feeReportTotalAfterDiscountedFee = (feeTotalOriginalCar - feeTotalDiscountedCar) + (feeTotalOriginalTaxi - feeTotalDiscountedTaxi) + (feeTotalOriginalTruck - feeTotalDiscountedTruck);
cout << "Item\t\t\t\t" << "Car\t" << "Taxi\t" << "Truck\t" << endl;
cout << "------------------------------------------------------\n";
cout << "Original fee\t\t\t" << "RM " << feeOriginalCar << "\t" << "RM " << feeOriginalTaxi << "\t" << "RM " << feeOriginalTruck << endl;
cout << "Quantity\t\t\t" << qtyVehicleCar << "\t" << qtyVehicleTaxi << "\t" << qtyVehicleTruck << endl;
cout << "Total original fee\t\t" << "RM " << feeTotalOriginalCar << "\t" << "RM " << feeTotalOriginalTaxi << "\t" << "RM " << feeTotalOriginalTruck << endl;
cout << "Discount rate\t\t\t" << rateDiscountCar << "%\t" << rateDiscountTaxi << "%\t" << rateDiscountTruck << "%\t" << endl;
cout << "Total discounted fee\t\t" << "RM " << feeTotalDiscountedCar << "\t" << "RM " << feeTotalDiscountedTaxi << "\t" << "RM " << feeTotalDiscountedTruck << endl;
cout << "Total after discounted fee\t" << "RM " << feeTotalAfterDiscountedCar << "\t" << "RM " << feeTotalAfterDiscountedTaxi << "\t" << "RM " << feeTotalAfterDiscountedTruck << endl;
cout << endl;
/* Displays output */
cout << "Total original fee\t\t:\t" << "RM " << feeReportTotalOriginalFee << endl;
cout << "Total discounted fee\t\t:\t" << "RM " << feeReportTotalDiscountedFee << endl;
cout << "Total after discounted fee\t:\t" << "RM " << feeReportTotalAfterDiscountedFee << endl;
cout << endl << endl;
/* Displays end line */
cout << "------------------- End of Program -------------------" << endl;
system("PAUSE");
return 0;
return 0;
}
答案 0 :(得分:1)
您似乎没有给feeReportTotalAfterDiscountedFee
类型。它的第一次出现似乎是在注释中,它们没有提供任何关于实际上是什么的指示。鉴于代码中其他变量的类型,我假设它是double
,但编译器不知道。
尝试将double
放在第一条注释行的feeReportTotalAfterDiscountedFee
前面(当然,在取消注释后)。