まず最初に: このコードは長すぎるので、かなり短縮できることはわかっています。ただし、それを短縮する方法については助けたくありません。いくつかの基本を理解しようとしているだけで、現在の問題は演算子と値の保存にあります。おそらくコードからわかるように、一連の if ステートメントを使用して特定の値を変数に格納し、それらの値を最後に文字列にまとめて表示しようとしています。コンパイラは私のコードを気に入らず、演算子関連のエラーを大量に表示します。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string type = "";
string color = "";
string invTypeCode = "";
string invColorCode = "";
string fullCode = "";
cout << "Use this program to determine inventory code of furniture.";
cout << "Enter type of furniture: ";
cin >> type;
if (type.length() == 1)
{
if (type == "1" or "2")
{
if (type == "1")
{
invTypeCode = "T47" << endl;
}
if (type == "2")
{
invTypeCode = "C47" << endl;
}
else
cout << "Invalid inventory code." << endl;
}}
else
cout << "Invalid inventory code." << endl;
cout << "Enter color code of furniture: ";
cin >> color;
if (color.length() == 1)
{
if (color == "1" or "2" or "3")
{
if (color == "1")
{
invColorCode = "41" << endl;
}
if (type == "2")
{
invColorCode = "25" << endl;
}
if (type == "3")
{
invColorCode = "30" << endl;
}
else
cout << "Invalid inventory code." << endl;
}}
else
cout << "Invalid inventory code." << endl;
fullCode = invTypeCode + invColorCode;
cout << fullcode << endl;
system("pause");
return 0;
}