帮助未定义和多字符成为常量

发布于 2024-10-31 12:03:23 字数 6737 浏览 1 评论 0原文

我不明白我做错了什么。我是新手,无法弄清楚为什么修剪类型未定义,并且“乙烯基内饰”有太多字符而无法成为常量。请帮助

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cctype>

using namespace std;

    void getIntroduction();
    void getBasePrice(double& BaseCost);
    void getEngineCost(double& EngineCost, string& EngineType);
    void getTrimCost(double& TrimCost, string& TrimType);
    void getRadioCost(double& RadioCost, string& RadioType);
    void calcTotalCost(double& BaseCost, double& EngineCost, double& TrimCost, double& RadioCost, double& ShippingCost, double& DealerCost);

int _tmain(int argc, _TCHAR* argv[])
{
    double ShippingCostOut;
    double DealerCostOut;
    double BaseCostOut;
    double EngineCostOut;
    double TrimCostOut;
    double RadioCostOut;
    double TotalCostOut;
    string EngineTypeOut;
    string TrimTypeOut;
    string RadioTypeOut;
    string ExitKey;

    ShippingCostOut = 500.00;
    DealerCostOut = 175.00;

    cout << endl;
    cout << endl;
    getIntroduction();
    cout <<endl;
    cout <<endl;
    cout << " Your selections will determine final Price" << endl;
    cout << endl;
    getBasePrice(BaseCostOut);
    cout<< endl;
    getEngineCost(EngineCostOut,EngineTypeOut); 
    cout<< endl;
    getTrimCost(TrimCostOut,TrimTypeOut);
    cout<< endl;
    getRadioCost(RadioCostOut,RadioTypeOut);
    cout<< endl;
    cout << endl;
    TotalCostOut = ShippingCostOut + DealerCostOut + BaseCostOut + EngineCostOut + TrimCostOut + RadioCostOut;
    system("CLS");
    cout << " Your selections result in:" << endl;
    cout << " Base Cost - $" << BaseCostOut << endl;
    cout << endl;
    cout << " " << EngineTypeOut << " - $" << EngineCostOut << endl;
    cout << endl;
    cout << " " << TrimTypeOut << " - $" << TrimCostOut << endl;
    cout << endl;
    cout << " " << RadioTypeOut << " - $" << RadioCostOut << endl;
    cout << endl;
    cout << " Shipping Cost - $" << ShippingCostOut << endl;
    cout << " Dealer Cost   - $" << DealerCostOut << endl;
    cout << endl;
    cout << " The total cost of the vehicle is: $" << TotalCostOut << endl;
    cout << endl;
    cout << "Enter any key and hit Enter to end program." << endl;
    cin >> ExitKey;

    return 0;

}

void getIntroduction ()
    {
        cout << "Universal Motors New Car Price Calculator" << endl;
        cout << " You will select your Options" << endl;
        cout << endl;
        cout << " The shipping cost - $500.00"<<endl;
        cout << " The dealer cost   - $175.00"<<endl;
        cout<< endl;


    }

void getBasePrice(double& BaseCost)
    {

            char BaseCheck;
            BaseCheck = 'A';
            cin.clear();
            cin.sync();


            do
            {
                BaseCheck = 'A';
                cout << endl;
                cout << " Please enter the base price for the new car: " << endl;
                cout << " Please enter Base Price in this format xxxxx.xx (x is a number):" <<endl;
                cout << endl;
                cout << "$ ";
                cin >> BaseCost;
                cout << BaseCost * 2;


            } while (BaseCheck == 'S');

    }

    void getEngineCost(double& EngineCost, string& EngineType)
    {
        char EngineLetter;
        do
        {
            cout << endl;
            cout << " Please choose your engine type: "<< endl;
            cout<< endl;
            cout << "  S - 6 cylinder engine - $150.00"<<endl;
            cout << "  E - 8 cylinder engine - $475.00"<<endl;
            cout << "  D - Diesel engine     - $750.00"<<endl;
            cout << endl;
            cout << " Please enter your engine type: ";
            cin >>  EngineLetter;


            switch (EngineLetter)
            {   

                case 'S':
                    EngineCost = 150.00;
                    EngineType = "6 cylinder engine";
                break;

                case 'E':
                    EngineCost = 475.00;
                    EngineType = "8 cylinder engine";
                break;

                case 'D':
                    EngineCost= 750.00;
                    EngineType = "Diesel engine";
                break;  

    }

void getTrimCost(double& TrimCost, string& TrimType);
    {
        char TrimChoice;
        do  
        {
            cout << endl;
            cout << "Please choose your Trim Type:" << endl;
            cout<< endl;
            cout << " V - Vinyl interior trim   - $50.00"<<endl;
            cout << " C - Cloth interior trim   - $225.00"<<endl;
            cout << " L - Leather interior trim - $800.00"<<endl;
            cout << endl;
            cout << " Please enter your Trim: ";
            cin >>  TrimChoice;

            switch (TrimChoice)
            {   
                case 'V':
                    double TrimCost = 50.00;
                    TrimType = 'Vinyl interior trim';
                break;

                case 'C':
                    TrimCost = 225.00;
                    TrimType = "Cloth interior trim";
                break;

            case 'L':
                TrimCost= 800.00;
                TrimType = "Leather interior trim";
            break;

    }

void getRadioCost(double& RadioCost, string& RadioType);
    {
        char RadioChoice;   
        do  
        {

            cout << endl;
            cout << "Please choose your Radio:" << endl;
            cout<< endl;
            cout << " C - AM/FM Radio - $100.00" << endl;
            cout << " P - CD/DVD      - $400.00" << endl;
            cout << endl;
            cout << " Enter Selection Please: ";
            cin >>  RadioChoice;


            if (RadioChoice == 'C')
            {
                double RadioCost = 100.00;
                RadioType = "AM/FM Radio";
            }

            else 
                if (RadioChoice == 'P')
                {
                    double RadioCost = 400.00;
                    RadioType = "CD/DVD";
                }
        }

I dont understand what Iam doing wrong. Iam a newbie and cant figure out why trimtype is undefined and 'Vinyl interior trim' has too many characters to be a constant.please help

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cctype>

using namespace std;

    void getIntroduction();
    void getBasePrice(double& BaseCost);
    void getEngineCost(double& EngineCost, string& EngineType);
    void getTrimCost(double& TrimCost, string& TrimType);
    void getRadioCost(double& RadioCost, string& RadioType);
    void calcTotalCost(double& BaseCost, double& EngineCost, double& TrimCost, double& RadioCost, double& ShippingCost, double& DealerCost);

int _tmain(int argc, _TCHAR* argv[])
{
    double ShippingCostOut;
    double DealerCostOut;
    double BaseCostOut;
    double EngineCostOut;
    double TrimCostOut;
    double RadioCostOut;
    double TotalCostOut;
    string EngineTypeOut;
    string TrimTypeOut;
    string RadioTypeOut;
    string ExitKey;

    ShippingCostOut = 500.00;
    DealerCostOut = 175.00;

    cout << endl;
    cout << endl;
    getIntroduction();
    cout <<endl;
    cout <<endl;
    cout << " Your selections will determine final Price" << endl;
    cout << endl;
    getBasePrice(BaseCostOut);
    cout<< endl;
    getEngineCost(EngineCostOut,EngineTypeOut); 
    cout<< endl;
    getTrimCost(TrimCostOut,TrimTypeOut);
    cout<< endl;
    getRadioCost(RadioCostOut,RadioTypeOut);
    cout<< endl;
    cout << endl;
    TotalCostOut = ShippingCostOut + DealerCostOut + BaseCostOut + EngineCostOut + TrimCostOut + RadioCostOut;
    system("CLS");
    cout << " Your selections result in:" << endl;
    cout << " Base Cost - $" << BaseCostOut << endl;
    cout << endl;
    cout << " " << EngineTypeOut << " - $" << EngineCostOut << endl;
    cout << endl;
    cout << " " << TrimTypeOut << " - $" << TrimCostOut << endl;
    cout << endl;
    cout << " " << RadioTypeOut << " - $" << RadioCostOut << endl;
    cout << endl;
    cout << " Shipping Cost - $" << ShippingCostOut << endl;
    cout << " Dealer Cost   - $" << DealerCostOut << endl;
    cout << endl;
    cout << " The total cost of the vehicle is: $" << TotalCostOut << endl;
    cout << endl;
    cout << "Enter any key and hit Enter to end program." << endl;
    cin >> ExitKey;

    return 0;

}

void getIntroduction ()
    {
        cout << "Universal Motors New Car Price Calculator" << endl;
        cout << " You will select your Options" << endl;
        cout << endl;
        cout << " The shipping cost - $500.00"<<endl;
        cout << " The dealer cost   - $175.00"<<endl;
        cout<< endl;


    }

void getBasePrice(double& BaseCost)
    {

            char BaseCheck;
            BaseCheck = 'A';
            cin.clear();
            cin.sync();


            do
            {
                BaseCheck = 'A';
                cout << endl;
                cout << " Please enter the base price for the new car: " << endl;
                cout << " Please enter Base Price in this format xxxxx.xx (x is a number):" <<endl;
                cout << endl;
                cout << "$ ";
                cin >> BaseCost;
                cout << BaseCost * 2;


            } while (BaseCheck == 'S');

    }

    void getEngineCost(double& EngineCost, string& EngineType)
    {
        char EngineLetter;
        do
        {
            cout << endl;
            cout << " Please choose your engine type: "<< endl;
            cout<< endl;
            cout << "  S - 6 cylinder engine - $150.00"<<endl;
            cout << "  E - 8 cylinder engine - $475.00"<<endl;
            cout << "  D - Diesel engine     - $750.00"<<endl;
            cout << endl;
            cout << " Please enter your engine type: ";
            cin >>  EngineLetter;


            switch (EngineLetter)
            {   

                case 'S':
                    EngineCost = 150.00;
                    EngineType = "6 cylinder engine";
                break;

                case 'E':
                    EngineCost = 475.00;
                    EngineType = "8 cylinder engine";
                break;

                case 'D':
                    EngineCost= 750.00;
                    EngineType = "Diesel engine";
                break;  

    }

void getTrimCost(double& TrimCost, string& TrimType);
    {
        char TrimChoice;
        do  
        {
            cout << endl;
            cout << "Please choose your Trim Type:" << endl;
            cout<< endl;
            cout << " V - Vinyl interior trim   - $50.00"<<endl;
            cout << " C - Cloth interior trim   - $225.00"<<endl;
            cout << " L - Leather interior trim - $800.00"<<endl;
            cout << endl;
            cout << " Please enter your Trim: ";
            cin >>  TrimChoice;

            switch (TrimChoice)
            {   
                case 'V':
                    double TrimCost = 50.00;
                    TrimType = 'Vinyl interior trim';
                break;

                case 'C':
                    TrimCost = 225.00;
                    TrimType = "Cloth interior trim";
                break;

            case 'L':
                TrimCost= 800.00;
                TrimType = "Leather interior trim";
            break;

    }

void getRadioCost(double& RadioCost, string& RadioType);
    {
        char RadioChoice;   
        do  
        {

            cout << endl;
            cout << "Please choose your Radio:" << endl;
            cout<< endl;
            cout << " C - AM/FM Radio - $100.00" << endl;
            cout << " P - CD/DVD      - $400.00" << endl;
            cout << endl;
            cout << " Enter Selection Please: ";
            cin >>  RadioChoice;


            if (RadioChoice == 'C')
            {
                double RadioCost = 100.00;
                RadioType = "AM/FM Radio";
            }

            else 
                if (RadioChoice == 'P')
                {
                    double RadioCost = 400.00;
                    RadioType = "CD/DVD";
                }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2024-11-07 12:03:23

问题可能出在这一行:

TrimType = 'Vinyl interior trim';

在 C 和 C++ 中,单引号 (') 指定 char 文字,即单个字符。但您的 TrimType 不是 char,它是 string,因此您必须使用双引号 ("):

TrimType = "Vinyl interior trim";

The problem is likely this line:

TrimType = 'Vinyl interior trim';

In C and C++, single quotes (') designate char literals, i.e., a single character. But your TrimType isn't a char, it's a string, so you have to use double quotes ("):

TrimType = "Vinyl interior trim";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文