Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
你愿意就我的程序计划给我反馈吗? 我想知道你们有没有人能给我一些关于C++程序的反馈?我是一名编程新手,因此,如果有任何关于如何提高代码效率的反馈,我将不胜感激。例如,我是否充分利用了DO/WHILE循环,还是有更好的方法?根据你所看到的,你能给它打10分吗。感谢所有打扰您或关心您的人 // Created by George Austin Bradley on 19/11/2019. // Copyright © 2019 George Austin Bradley. All rights reserved. #include <iostream> #include <iomanip> using namespace std; //1. This displays the car menu items. void display_menu() { cout << "\nMENU"; cout << "\n1. Blue Nissan Skyline"; cout << "\n2. Red Mini"; cout << "\n3. Black Land Rover"; cout << "\n"; } //This procedure proccesses the user's selection and all information regarding price and name of car are then transferred to transaction variables. void selectedCar(double &dCostOfChosenCar, string &sNameOfChosenCar) { int iSelectionFromMenu = 0; double dCar1 = 1000, dCar2 = 3000, dCar3 = 4000; string sCar1 = "Blue Nissan Skyline", sCar2 = "Red Mini", sCar3 = "Black Land Rover"; do{ display_menu(); cout << "\nChoose a car that you'd wish to buy from the menu (1 - 3): "; cin >> iSelectionFromMenu; if(iSelectionFromMenu == 1) { sNameOfChosenCar = sCar1; dCostOfChosenCar = dCar1; } else if (iSelectionFromMenu == 2){ sNameOfChosenCar = sCar2; dCostOfChosenCar = dCar2; } else if (iSelectionFromMenu == 3) { sNameOfChosenCar = sCar3; dCostOfChosenCar = dCar3; } else { cout << "\nPlease enter valid number!"; } }while(iSelectionFromMenu < 0 || iSelectionFromMenu > 3); } //This procedure gets from the user their preferred finance plan through their input. void FinanceLength(int &iFinanceLength) { do{ cout << "\nHow long do you wish for your finance plan to last? (1 - 4 years): "; cin >> iFinanceLength; if (iFinanceLength < 0 || iFinanceLength > 4) { cout << "\nOops, try again! Please enter between 1 - 4!"; } }while(iFinanceLength < 0 || iFinanceLength > 4); } //This procedure gets the user's deposit. void DepositMoney(double &dDepositAmount, double dCostOfChosenCar) { do{ cout << "\nEnter deposit amount (minimum £500 accepted): £"; cin >> dDepositAmount; if (dDepositAmount < 500) { cout << "\nTry again! Deposit an amount greater than or equal to £500."; } }while(dDepositAmount < 500); } //This function calculates the amount of money the user has to pay after deposit, added tax and charge percentage of 10% double TotalLeftToPay(double iFinanceLength, double dDepositAmount, double dCostOfChosenCar) { double dChargePercentage = 0.10; double dTotalLeftToPay = dCostOfChosenCar + (dCostOfChosenCar * dChargePercentage) - dDepositAmount + 135; return dTotalLeftToPay; } //This calculates monthly payments. double MonthlyPayments(double dTotalLeftToPay, int iFinanceLength) { double dMonthlyPayments = (dTotalLeftToPay / iFinanceLength) / 12; return dMonthlyPayments; } //This asks the user whether they'd like to restart the application. void RestartOptions(char &cOption, bool *bExit) { do{ cout << "\nDo you wish to restart your application? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y') { *bExit = false; } else if (cOption == 'N' || cOption == 'n') { *bExit = true; } else { cout << "Sorry, that's an invalid input, please try again!"; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } //This string function returns either year or years (plural) string YearOrYears(int iFinanceLength) { if (iFinanceLength > 1) { return "years"; } else { return "year"; } } //This displays receipt of the user's transaction. void Receipt(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, char cOption, bool *bExit) { cout << "\nHi, " << sUserName << ". "; cout << "\nYou have chosen " << sNameOfChosenCar << "."; cout << "\nYour finance plan timescale is " << iFinanceLength << " " << YearOrYears(iFinanceLength) << "."; cout << "\nYou've deposited £" << dDepositAmount << "."; double dTotalLeftToPay = TotalLeftToPay(iFinanceLength, dDepositAmount, dCostOfChosenCar); cout << "\nTotal left to pay: £" << dTotalLeftToPay; double dMonthlyPayments = MonthlyPayments(dTotalLeftToPay, iFinanceLength); cout << "\nMonthly Payments: £" << dMonthlyPayments; RestartOptions(cOption, bExit); } //This asks the user whether they're happy with the options of they've chosen. void AcceptDeclineOptions(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, bool *bExit) { char cOption = 0; do { cout << "\nDo you agree with the options you've chosen? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y' || cOption == 'N' || cOption == 'n') { if (cOption == 'Y' || cOption == 'y') { Receipt(sUserName, sNameOfChosenCar, iFinanceLength, dDepositAmount, dCostOfChosenCar, cOption, bExit); } } else { cout << "\nSorry, that's not a valid command."; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } int main() { bool *bExit = new bool; string sNameOfChosenCar = ""; double dCostOfChosenCar = 0; int iFinanceLength = 0; double dDepositAmount = 0; *bExit = false; do{ cout << "Welcome!"; string sUserName = ""; cout << "\nEnter your name: "; cin >> sUserName; selectedCar(dCostOfChosenCar, sNameOfChosenCar); FinanceLength(iFinanceLength); DepositMoney(dDepositAmount, dCostOfChosenCar); AcceptDeclineOptions(sUserName, sNameOfChosenCar, iFinanceLength,dDepositAmount, dCostOfChosenCar, bExit); }while(*bExit == false); delete bExit; } //由乔治·奥斯汀·布拉德利于2019年11月19日创作。 //版权所有©2019乔治·奥斯汀·布拉德利。版权所有。 #包括 #包括 使用名称空间std; //1. 这将显示汽车菜单项。 无效显示菜单() { cout_C++ - Fatal编程技术网

你愿意就我的程序计划给我反馈吗? 我想知道你们有没有人能给我一些关于C++程序的反馈?我是一名编程新手,因此,如果有任何关于如何提高代码效率的反馈,我将不胜感激。例如,我是否充分利用了DO/WHILE循环,还是有更好的方法?根据你所看到的,你能给它打10分吗。感谢所有打扰您或关心您的人 // Created by George Austin Bradley on 19/11/2019. // Copyright © 2019 George Austin Bradley. All rights reserved. #include <iostream> #include <iomanip> using namespace std; //1. This displays the car menu items. void display_menu() { cout << "\nMENU"; cout << "\n1. Blue Nissan Skyline"; cout << "\n2. Red Mini"; cout << "\n3. Black Land Rover"; cout << "\n"; } //This procedure proccesses the user's selection and all information regarding price and name of car are then transferred to transaction variables. void selectedCar(double &dCostOfChosenCar, string &sNameOfChosenCar) { int iSelectionFromMenu = 0; double dCar1 = 1000, dCar2 = 3000, dCar3 = 4000; string sCar1 = "Blue Nissan Skyline", sCar2 = "Red Mini", sCar3 = "Black Land Rover"; do{ display_menu(); cout << "\nChoose a car that you'd wish to buy from the menu (1 - 3): "; cin >> iSelectionFromMenu; if(iSelectionFromMenu == 1) { sNameOfChosenCar = sCar1; dCostOfChosenCar = dCar1; } else if (iSelectionFromMenu == 2){ sNameOfChosenCar = sCar2; dCostOfChosenCar = dCar2; } else if (iSelectionFromMenu == 3) { sNameOfChosenCar = sCar3; dCostOfChosenCar = dCar3; } else { cout << "\nPlease enter valid number!"; } }while(iSelectionFromMenu < 0 || iSelectionFromMenu > 3); } //This procedure gets from the user their preferred finance plan through their input. void FinanceLength(int &iFinanceLength) { do{ cout << "\nHow long do you wish for your finance plan to last? (1 - 4 years): "; cin >> iFinanceLength; if (iFinanceLength < 0 || iFinanceLength > 4) { cout << "\nOops, try again! Please enter between 1 - 4!"; } }while(iFinanceLength < 0 || iFinanceLength > 4); } //This procedure gets the user's deposit. void DepositMoney(double &dDepositAmount, double dCostOfChosenCar) { do{ cout << "\nEnter deposit amount (minimum £500 accepted): £"; cin >> dDepositAmount; if (dDepositAmount < 500) { cout << "\nTry again! Deposit an amount greater than or equal to £500."; } }while(dDepositAmount < 500); } //This function calculates the amount of money the user has to pay after deposit, added tax and charge percentage of 10% double TotalLeftToPay(double iFinanceLength, double dDepositAmount, double dCostOfChosenCar) { double dChargePercentage = 0.10; double dTotalLeftToPay = dCostOfChosenCar + (dCostOfChosenCar * dChargePercentage) - dDepositAmount + 135; return dTotalLeftToPay; } //This calculates monthly payments. double MonthlyPayments(double dTotalLeftToPay, int iFinanceLength) { double dMonthlyPayments = (dTotalLeftToPay / iFinanceLength) / 12; return dMonthlyPayments; } //This asks the user whether they'd like to restart the application. void RestartOptions(char &cOption, bool *bExit) { do{ cout << "\nDo you wish to restart your application? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y') { *bExit = false; } else if (cOption == 'N' || cOption == 'n') { *bExit = true; } else { cout << "Sorry, that's an invalid input, please try again!"; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } //This string function returns either year or years (plural) string YearOrYears(int iFinanceLength) { if (iFinanceLength > 1) { return "years"; } else { return "year"; } } //This displays receipt of the user's transaction. void Receipt(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, char cOption, bool *bExit) { cout << "\nHi, " << sUserName << ". "; cout << "\nYou have chosen " << sNameOfChosenCar << "."; cout << "\nYour finance plan timescale is " << iFinanceLength << " " << YearOrYears(iFinanceLength) << "."; cout << "\nYou've deposited £" << dDepositAmount << "."; double dTotalLeftToPay = TotalLeftToPay(iFinanceLength, dDepositAmount, dCostOfChosenCar); cout << "\nTotal left to pay: £" << dTotalLeftToPay; double dMonthlyPayments = MonthlyPayments(dTotalLeftToPay, iFinanceLength); cout << "\nMonthly Payments: £" << dMonthlyPayments; RestartOptions(cOption, bExit); } //This asks the user whether they're happy with the options of they've chosen. void AcceptDeclineOptions(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, bool *bExit) { char cOption = 0; do { cout << "\nDo you agree with the options you've chosen? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y' || cOption == 'N' || cOption == 'n') { if (cOption == 'Y' || cOption == 'y') { Receipt(sUserName, sNameOfChosenCar, iFinanceLength, dDepositAmount, dCostOfChosenCar, cOption, bExit); } } else { cout << "\nSorry, that's not a valid command."; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } int main() { bool *bExit = new bool; string sNameOfChosenCar = ""; double dCostOfChosenCar = 0; int iFinanceLength = 0; double dDepositAmount = 0; *bExit = false; do{ cout << "Welcome!"; string sUserName = ""; cout << "\nEnter your name: "; cin >> sUserName; selectedCar(dCostOfChosenCar, sNameOfChosenCar); FinanceLength(iFinanceLength); DepositMoney(dDepositAmount, dCostOfChosenCar); AcceptDeclineOptions(sUserName, sNameOfChosenCar, iFinanceLength,dDepositAmount, dCostOfChosenCar, bExit); }while(*bExit == false); delete bExit; } //由乔治·奥斯汀·布拉德利于2019年11月19日创作。 //版权所有©2019乔治·奥斯汀·布拉德利。版权所有。 #包括 #包括 使用名称空间std; //1. 这将显示汽车菜单项。 无效显示菜单() { cout

你愿意就我的程序计划给我反馈吗? 我想知道你们有没有人能给我一些关于C++程序的反馈?我是一名编程新手,因此,如果有任何关于如何提高代码效率的反馈,我将不胜感激。例如,我是否充分利用了DO/WHILE循环,还是有更好的方法?根据你所看到的,你能给它打10分吗。感谢所有打扰您或关心您的人 // Created by George Austin Bradley on 19/11/2019. // Copyright © 2019 George Austin Bradley. All rights reserved. #include <iostream> #include <iomanip> using namespace std; //1. This displays the car menu items. void display_menu() { cout << "\nMENU"; cout << "\n1. Blue Nissan Skyline"; cout << "\n2. Red Mini"; cout << "\n3. Black Land Rover"; cout << "\n"; } //This procedure proccesses the user's selection and all information regarding price and name of car are then transferred to transaction variables. void selectedCar(double &dCostOfChosenCar, string &sNameOfChosenCar) { int iSelectionFromMenu = 0; double dCar1 = 1000, dCar2 = 3000, dCar3 = 4000; string sCar1 = "Blue Nissan Skyline", sCar2 = "Red Mini", sCar3 = "Black Land Rover"; do{ display_menu(); cout << "\nChoose a car that you'd wish to buy from the menu (1 - 3): "; cin >> iSelectionFromMenu; if(iSelectionFromMenu == 1) { sNameOfChosenCar = sCar1; dCostOfChosenCar = dCar1; } else if (iSelectionFromMenu == 2){ sNameOfChosenCar = sCar2; dCostOfChosenCar = dCar2; } else if (iSelectionFromMenu == 3) { sNameOfChosenCar = sCar3; dCostOfChosenCar = dCar3; } else { cout << "\nPlease enter valid number!"; } }while(iSelectionFromMenu < 0 || iSelectionFromMenu > 3); } //This procedure gets from the user their preferred finance plan through their input. void FinanceLength(int &iFinanceLength) { do{ cout << "\nHow long do you wish for your finance plan to last? (1 - 4 years): "; cin >> iFinanceLength; if (iFinanceLength < 0 || iFinanceLength > 4) { cout << "\nOops, try again! Please enter between 1 - 4!"; } }while(iFinanceLength < 0 || iFinanceLength > 4); } //This procedure gets the user's deposit. void DepositMoney(double &dDepositAmount, double dCostOfChosenCar) { do{ cout << "\nEnter deposit amount (minimum £500 accepted): £"; cin >> dDepositAmount; if (dDepositAmount < 500) { cout << "\nTry again! Deposit an amount greater than or equal to £500."; } }while(dDepositAmount < 500); } //This function calculates the amount of money the user has to pay after deposit, added tax and charge percentage of 10% double TotalLeftToPay(double iFinanceLength, double dDepositAmount, double dCostOfChosenCar) { double dChargePercentage = 0.10; double dTotalLeftToPay = dCostOfChosenCar + (dCostOfChosenCar * dChargePercentage) - dDepositAmount + 135; return dTotalLeftToPay; } //This calculates monthly payments. double MonthlyPayments(double dTotalLeftToPay, int iFinanceLength) { double dMonthlyPayments = (dTotalLeftToPay / iFinanceLength) / 12; return dMonthlyPayments; } //This asks the user whether they'd like to restart the application. void RestartOptions(char &cOption, bool *bExit) { do{ cout << "\nDo you wish to restart your application? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y') { *bExit = false; } else if (cOption == 'N' || cOption == 'n') { *bExit = true; } else { cout << "Sorry, that's an invalid input, please try again!"; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } //This string function returns either year or years (plural) string YearOrYears(int iFinanceLength) { if (iFinanceLength > 1) { return "years"; } else { return "year"; } } //This displays receipt of the user's transaction. void Receipt(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, char cOption, bool *bExit) { cout << "\nHi, " << sUserName << ". "; cout << "\nYou have chosen " << sNameOfChosenCar << "."; cout << "\nYour finance plan timescale is " << iFinanceLength << " " << YearOrYears(iFinanceLength) << "."; cout << "\nYou've deposited £" << dDepositAmount << "."; double dTotalLeftToPay = TotalLeftToPay(iFinanceLength, dDepositAmount, dCostOfChosenCar); cout << "\nTotal left to pay: £" << dTotalLeftToPay; double dMonthlyPayments = MonthlyPayments(dTotalLeftToPay, iFinanceLength); cout << "\nMonthly Payments: £" << dMonthlyPayments; RestartOptions(cOption, bExit); } //This asks the user whether they're happy with the options of they've chosen. void AcceptDeclineOptions(string &sUserName, string &sNameOfChosenCar, int &iFinanceLength, double &dDepositAmount, double &dCostOfChosenCar, bool *bExit) { char cOption = 0; do { cout << "\nDo you agree with the options you've chosen? (y/n): "; cin >> cOption; if (cOption == 'Y' || cOption == 'y' || cOption == 'N' || cOption == 'n') { if (cOption == 'Y' || cOption == 'y') { Receipt(sUserName, sNameOfChosenCar, iFinanceLength, dDepositAmount, dCostOfChosenCar, cOption, bExit); } } else { cout << "\nSorry, that's not a valid command."; } }while(cOption != 'y' && cOption != 'Y' && cOption != 'n' && cOption != 'N'); } int main() { bool *bExit = new bool; string sNameOfChosenCar = ""; double dCostOfChosenCar = 0; int iFinanceLength = 0; double dDepositAmount = 0; *bExit = false; do{ cout << "Welcome!"; string sUserName = ""; cout << "\nEnter your name: "; cin >> sUserName; selectedCar(dCostOfChosenCar, sNameOfChosenCar); FinanceLength(iFinanceLength); DepositMoney(dDepositAmount, dCostOfChosenCar); AcceptDeclineOptions(sUserName, sNameOfChosenCar, iFinanceLength,dDepositAmount, dCostOfChosenCar, bExit); }while(*bExit == false); delete bExit; } //由乔治·奥斯汀·布拉德利于2019年11月19日创作。 //版权所有©2019乔治·奥斯汀·布拉德利。版权所有。 #包括 #包括 使用名称空间std; //1. 这将显示汽车菜单项。 无效显示菜单() { cout,c++,C++,我是在电话上输入的,而不是在编译器上,我想为任何语法错误道歉 优点: 你已经掌握了格式和结构的基本知识 你的代码干净易读。(不能强调这有多重要) 您的变量命名也很好。我指的是类型前缀(s)字符串,(d)双精度等 缺点: 您对语言功能的使用有限,例如类、数组和逻辑语句(缺乏经验,将被淘汰) 您正在路上。我建议您为您的汽车对象创建一个类。 下一个函数确实显示了一辆车的“类”和“向量”会更好。你已经将每辆车的每个价格和描述硬编码到它们自己的变量中。因此,如果你想添加更多的车,你必须添加更多的

我是在电话上输入的,而不是在编译器上,我想为任何语法错误道歉

优点:

  • 你已经掌握了格式和结构的基本知识
  • 你的代码干净易读。(不能强调这有多重要)
  • 您的变量命名也很好。我指的是类型前缀(s)字符串,(d)双精度等
缺点:

  • 您对语言功能的使用有限,例如类、数组和逻辑语句(缺乏经验,将被淘汰)
您正在路上。
我建议您为您的汽车对象创建一个类。

下一个函数确实显示了一辆车的“类”和“向量”会更好。你已经将每辆车的每个价格和描述硬编码到它们自己的变量中。因此,如果你想添加更多的车,你必须添加更多的变量。这将变得重复

void selectedCar(double &dCostOfChosenCar, string &sNameOfChosenCar)
{
    int iSelectionFromMenu = -1;
    do{
        display_menu();
        cout << "\nChoose a car that you'd wish to buy from the menu (1 - " 
             << car_list.size() << "): ";
        cin >> iSelectionFromMenu;
        if(iSelectionFromMenu >= 0 && iSelectionFromMenu < car_list.size())
        {
            sNameOfChosenCar = car_list[iSelectionFromMenu].getName();
            dCostOfChosenCar = car_list[iSelectionFromMenu].getPrice();
        }
        else
        {
            cout << "\nPlease enter valid number!";
            iSelectionFromMenu = -1
        }
    }while(iSelectionFromMenu  == -1);
}
您的下一个函数接受用户输入,并比较大小写。 这看起来是一个很好的时间来介绍

在“void AcceptDeclineOptions()”中,switch语句将非常有效

现在,您可以在main()中执行一些额外的步骤。首先,将所有汽车放入“汽车列表”

int main()
{
    car_list.append(cCar("Blue Nissan Skyline", 1000));
    car_list.append(cCar("Red Mini", 3000));
    car_list.append(cCar("Black Land Rover", 4000));

    bool bExit = false;
    string sNameOfChosenCar = "";
    double dCostOfChosenCar = 0;
    int iFinanceLength = 0;
    double dDepositAmount = 0;

    do{
        cout << "Welcome!";
        string sUserName = "";
        cout << "\nEnter your name: ";
        cin >> sUserName;

        selectedCar(dCostOfChosenCar, sNameOfChosenCar);
        FinanceLength(iFinanceLength);
        DepositMoney(dDepositAmount, dCostOfChosenCar);
        AcceptDeclineOptions(sUserName, sNameOfChosenCar, iFinanceLength,dDepositAmount, dCostOfChosenCar, bExit);

    }while(!bExit);
}
intmain()
{
附加(cCar(“蓝色日产天际线”,1000));
车辆清单。附加(cCar(“红色迷你”,3000));
附加汽车清单(cCar(“黑色路虎”,4000));
bool-bExit=false;
字符串sNameOfChosenCar=“”;
双dCostOfChosenCar=0;
int-iFinanceLength=0;
双倍金额=0;
做{
库特苏瑟南;
所选CAR(DCOSTOFCHOSECAR、SNAMEOFCHOSECAR);
财务长度(i财务长度);
存款(存款金额、存款金额);
接受decline期权(sUserName、SNAMEOFCHOSECAR、iFinanceLength、DDepositionAmount、DCOSTOFCHOSECAR、bExit);
}而(!bExit);
}

我相信你的问题更适合于
bool*bExit=new bool;
——为什么?
bool bExit;
是你所需要的一切。出于某种原因,我以前试过,但它似乎不起作用,也就是说,它不会在主()中退出程序.我想我应该使用指针,然后它就起作用了。我又试了一次,现在它起作用了,我以前肯定做错了什么。谢谢你的帮助!stackoverflow.com不是用来提供“反馈”的。这是离题。codereview更适合于此。我投票将此问题作为离题结束,因为它更适合codereview.stackexchange.comHi Ron,我最初开始使用switch语句,但不知道在达到默认值时如何继续循环,所以我切换了(没有双关语)到IF语句。我完全忘记/不知道“继续”语句。非常感谢您简化和提高了代码的效率,并向我展示了编写if语句的另一种方法。我将进一步研究类!我非常感谢您的反馈,我学到了很多!只是一个问题,您在哪里使用“append”这个词,这是指push_back吗?是的,我最近一直在做很多python。对此很抱歉
void selectedCar(double &dCostOfChosenCar, string &sNameOfChosenCar)
{
    int iSelectionFromMenu = -1;
    do{
        display_menu();
        cout << "\nChoose a car that you'd wish to buy from the menu (1 - " 
             << car_list.size() << "): ";
        cin >> iSelectionFromMenu;
        if(iSelectionFromMenu >= 0 && iSelectionFromMenu < car_list.size())
        {
            sNameOfChosenCar = car_list[iSelectionFromMenu].getName();
            dCostOfChosenCar = car_list[iSelectionFromMenu].getPrice();
        }
        else
        {
            cout << "\nPlease enter valid number!";
            iSelectionFromMenu = -1
        }
    }while(iSelectionFromMenu  == -1);
}
void FinanceLength(int &iFinanceLength)
void DepositMoney(double &dDepositAmount, double dCostOfChosenCar)
double TotalLeftToPay(double iFinanceLength, double dDepositAmount, double dCostOfChosenCar)
double MonthlyPayments(double dTotalLeftToPay, int iFinanceLength)
void RestartOptions(char &cOption, bool *bExit)
{
    do{
        cout << "\nDo you wish to restart your application? (y/n): ";
        cin >> cOption;
        switch(cOption){
            case 'Y':
            case 'y':
                *bExit = false;
                break;
            case 'N':
            case 'n':
                *bExit = true;
                break;
            default:
                cout << "Sorry, that's an invalid input, please try again!";
                continue; //keeps us in the do, while loop
        }
        break; //exits loop
    }while(1);
}
//This string function returns either year or years (plural)
string YearOrYears(int iFinanceLength)
{
    return (iFinanceLength > 1)? "years" : "year"
}
int main()
{
    car_list.append(cCar("Blue Nissan Skyline", 1000));
    car_list.append(cCar("Red Mini", 3000));
    car_list.append(cCar("Black Land Rover", 4000));

    bool bExit = false;
    string sNameOfChosenCar = "";
    double dCostOfChosenCar = 0;
    int iFinanceLength = 0;
    double dDepositAmount = 0;

    do{
        cout << "Welcome!";
        string sUserName = "";
        cout << "\nEnter your name: ";
        cin >> sUserName;

        selectedCar(dCostOfChosenCar, sNameOfChosenCar);
        FinanceLength(iFinanceLength);
        DepositMoney(dDepositAmount, dCostOfChosenCar);
        AcceptDeclineOptions(sUserName, sNameOfChosenCar, iFinanceLength,dDepositAmount, dCostOfChosenCar, bExit);

    }while(!bExit);
}