编写一个简单的代码并遇到了一个我不知道如何处理的问题。我尝试通过搜索对其进行调查,但没有发现任何帮助,而且每个人的答案都超出了我的想象。请有人像对小孩一样解释这个,哈哈。谢谢。
#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;
}