Suggestions welcome

So I'm trying to create a string. Based on the selection entered by the user, the program will store a sequence in the string. Then the program will ask the next question and add the last 2 digits of the sequence to the string.

Problem is I don't know the best way to do that using a string.

***The 2nd if sequence is left blank since I don't know how to add to a string***
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string invcode;
	int type;
	int color;

    cout<<"Enter (1) for table or (2) for chair"<<endl;
	cout<<"Enter the type of product you would like: "<<endl;
	cin>>type;

	if (type=1)
	{
	    invcode="T47";
	}
	else if (type=2)
	{
	    invcode="C47";
	}
	else
	{
	    cout<<"Invalid selection";
	}

	cout<<"Enter (1) for Red, (2) for Black, (3) for Green"<<endl;
	cout<<"Enter the type of color you would like: "<<endl;
	cin>>color;

	if(color=1)
	{

	}
    else if(color=2)
    {

    }
    else if(color=3)
    {

    }
    else
    {
        cout<<"Invalid Selection";
    }

	system("pause");
	return 0;
}
Last edited on
Thanks for the link, but I continued to play with it a little and figured it out. This seems to work for what I need. Please feel free to use/tweak as needed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string invcode;
	string type;
	string color;
	int product;

    cout<<"Enter (1) for table or (2) for chair"<<endl;
	cout<<"Enter the type of product you would like: ";
	cin>>product;

	if (product==1)
	{
	    type="T47";
	}
	else if (product==2)
	{
	    type="C47";
	}
	else
	{
	    cout<<"Invalid selection";
	}

	cout<<"Enter (1) for Red, (2) for Black, (3) for Green"<<endl;
	cout<<"Enter the type of color you would like: ";
	cin>>product;

	if(product==1)
	{
        color="41";
	}
    else if(product==2)
    {
        color="25";

    }
    else if(product==3)
    {
        color="30";

    }
    else
    {
        cout<<"Invalid Selection";
    }

    invcode=type+color;
    cout<<invcode<<endl<<endl;

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.