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***
#include <iostream>
#include <string>
usingnamespace 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";
}
elseif (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)
{
}
elseif(color=2)
{
}
elseif(color=3)
{
}
else
{
cout<<"Invalid Selection";
}
system("pause");
return 0;
}
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.
#include <iostream>
#include <string>
usingnamespace 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";
}
elseif (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";
}
elseif(product==2)
{
color="25";
}
elseif(product==3)
{
color="30";
}
else
{
cout<<"Invalid Selection";
}
invcode=type+color;
cout<<invcode<<endl<<endl;
system("pause");
return 0;
}