gpt4 book ai didi

c++ - 变量类型的问题

转载 作者:行者123 更新时间:2023-11-30 03:57:02 24 4
gpt4 key购买 nike

<分区>

我应该制作一个运输程序,询问用户一些基本问题。以下是说明:在线购物者在网络上搜索商品并从税率最低的州购买。编写一个简单的 C++ 程序来执行以下操作:向用户询问商品的单价、购物者要购买的商品数量、第一个州的名称、第一个州的税率、商品的名称第二州和第二州的税率。然后,计算每个州的总成本并决定购物者应该从哪个州购买商品。向购物者显示以下信息:单位商品成本、购买的商品数量、第一州的名称和税率、第二州的名称和税率,以及您对购物者应该从哪个州购买的建议.

列出程序中的所有文字和变量。

到目前为止,这是我的代码:

#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{
double itemPrice, numberItem, taxRate, totalCost;
double stateTax1, stateTax2;
int stateName1, stateName2;

// ask the item's price
cout << "What is the price of the item?\n";
cin >> itemPrice;

// ask the # items
cout << "How many items are you going to purchase?\n";
cin >> numberItem;

// ask the name of the first state
cout << "What state are you having it shipped to?\n";
cin >> stateName1;

// ask the tax rate of the first state
cout << "What is the tax rate in " << stateName1 << "?\n";
cin >> stateTax1;

// ask the name of the second state
cout << "What state are you having shipped from?\n";
cin >> stateName2;

// ask the tax rate of the second state
cout << "What is the tax rate in " << stateName2 << "?\n";
cin >> stateTax2;

// first if the first state has a lower tax rate
// else if second state has lower tax rate
if (stateTax1 < stateTax2)
{
totalCost = itemPrice * numberItem * stateTax1;

cout << "The item cost is " << itemPrice << ".\n";
cout << "The number of items is " << numberItem << ".\n";
cout << "The name of the first state is " << stateName1 << ".\n";
cout << "The tax rate of the first state is " << stateTax1 << ".\n";
cout << "The name of the second state is " << stateName2 << ".\n";
cout << "The tax rate of the second state is " << stateTax2 << ".\n";
cout << "You should consider purchasing the item from " << stateName1 << ".\n";
}
else
{
totalCost = itemPrice * numberItem * stateTax2;

cout << "The item cost is " << itemPrice << ".\n";
cout << "The number of items is " << numberItem << ".\n";
cout << "The name of the first state is " << stateName1 << ".\n";
cout << "The tax rate of the first state is " << stateTax1 << ".\n";
cout << "The name of the second state is " << stateName2 << ".\n";
cout << "The tax rate of the second state is " << stateTax2 << ".\n";
cout << "You should consider purchasing the item from " << stateName2 << ".\n";
}
return 0;
}

我的问题是如何让 stateName 变量正常工作。我确信这是我应该知道但我不知道的一些基本字符串。除此之外,我相信我的其余代码都可以正常工作。尽管任何和所有提示将不胜感激。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com