help with strings

i have to write a lab but i am completly stuck. i tried looking over the teachers notes and asking her questions but it didnt really help. could someone please give me a hand?

this is the program

An office furniture company sells furniture in three colors: red, black and green. Every item in their inventory system has a 5-character code. The last two characters are always used to represent color. If an item is red, the last two characters are “41”. If an item is black, the last two characters are “25”. If an item is green, the last two characters are “30”. Ask the user to enter a 5-character code. Use the last 2 characters to determine the color. Display the color in the console window (“Red”, “Black” or “Green”). If the inventory code is not exactly 5 characters long, or if the last two characters are neither “41”, “25” nor “30”, display an error message (“Invalid inventory code”). [Hint: Use the substr function to extract the last two characters of the string and see whether the extracted substring is “41”, “25” or “30”).

so far this is what i have

#include <iostream>
#include <string>
using namespace std;

int main()
{
string code = "";
string color = "";

cout << "Enter the inventory code: ";
getline(cin, code);


if (code.substr(4, 5) )
{
code = code.substr(3);
}
{
code = code.substr(4, 5);

if (code = 25)
{
cout << "Black" << endl;

else if (code = 41)
cout << "Red" << endl;

else if (code = 30)
cout << "Green" << endl;

else if(code.size() != 5)
cout << "Invalid inventory code!";
}
}

system ("pause")
return 0;
put your code in the /code tags please
Topic archived. No new replies allowed.