Writing a simple code and ran into a problem I\'m not sure how to deal with. I tried looking into it with a search but nothing I found was much help and everyone\'s answers wer
#include
#include
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 == "fourty five") // you declared lastTwoChars as string therefore you have to compare letters not integers which are numbers.
{
cout << "Red";
}
if (lastTwoChars == "twenty five") //same
{
cout << "Black";
}
if (lastTwoChars == "thirty") // same
{
cout << "Green";
}
}
else
cout << "Invalid inventory code." << endl;
cin.get(); // better than system("pause");
return 0;
}