need help with homework.

i need to help writing this out. i'm stuck

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”).
Try it out, and submit the code you write. We'll guide you from there.
i dont know where to start...i'm stuck writing out ipo chart for this

#include <iostream>
#include <string>

using namespace std;

int main()
{
I added a little bit, but you need to figure out the rest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main()
{
    string invCode;
    string color;
    
    cout << "Enter the inventory code: ";
    cin >> invCode;
    
    if(invCode.size() != 5)
    cout << "Invalid inventory code!";
}


This allows the user to enter a number, and checks it's length. You now need to check the last two numbers using the substr command. If the last two numbers don't equal what they should, display an error. If it does equal what it should, display the color. Make sense?
What are you learning during this assignment? structs? classes? functions? variables? we need details.
Topic archived. No new replies allowed.