簡単なコードを書いていて、対処方法がわからない問題に遭遇しました。検索して調べてみましたが、あまり役に立ちませんでした.みんなの答えは私の頭の少し上にありました. 誰か小さな子供に説明するように説明してください(笑)。ありがとう。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string invCode = "";
string lastTwoChars = "";
cout << "Use this program to determine color of furniture.";
cout << "Enter five-character inventory code: ";
cin >> invCode;
if (invCode.length() == 5)
{
lastTwoChars = invCode.substr(3,2);
if (lastTwoChars == 41)
{
cout << "Red";
}
if (lastTwoChars == 25)
{
cout << "Black";
}
if (lastTwoChars == 30)
{
cout << "Green";
}
}
else
cout << "Invalid inventory code." << endl;
system("pause");
return 0;
}