You are using a version without Ads of this website. Please, consider donating:

### Help with strings

I don't know why this code isn't working. It only returns T4741 no matter what I enter.

EDIT: This is the original problem

PROGRAM 2

The office furniture company in Program 1 wants another program to generate inventory code. They sell office chairs and tables in three colors. All inventory codes consist of 5 characters. If the product is a chair, the first three characters are “C47”. If the product is a table, the first three characters are “T47”. The last two characters are used to code color: “41” for red, “25” for black” and “30” for green. Write a program to do the following. First ask the user to enter type of product (e.g. “Enter 1 for table or 2 for chair”). Then ask the user to enter color (e.g. “Enter 1 for red, 2 for black or 3 for green). Generate and display the inventory code based on the information entered by the user. For example, if the user chooses chair and red, the inventory code generated by the program should be “C4741”. If the user enters wrong type or wrong color, display “Invalid input”.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````// Problem 2 // Created By: Tucker Peebles on 12/4/12 #include #include using namespace std; int main() { string first = ""; string last = ""; const string invalid = "Invalid input"; int type = 0; int color = 0; cout << "Enter 1 for a table or 2 for a chair: " <> type; if (type = 1) { first = "T47"; } else if (type = 2) { first = "C47"; } else { cout << invalid <> color; if (color = 1) { last = "41"; } else if (color = 2) { last = "25"; } else if (color = 3) { last = "30"; } else { cout << invalid <
Last edited on
`if (type = 1)`

When checking for equality you must use ==, not =. Otherwise it will assign 1 to "type" and return true.
Last edited on
thanks
Topic archived. No new replies allowed.