The problem is my error output keeps stating "Expression must have a constant value" four times.
I've used this site and tried allocating memory and deleting it and that did nothing whatsoever. I changed "mystr.length();" to a number and while that allowed the program to run, it provided invalid results.
char letter = 'Y';
int position = 0;
string productNames[7] =
{ "Pen", "Paper", "Computer", "Pepsi", "Coke", "Book", "Scanner" };
int prizeOfproducts[7] = { 10, 2, 5000, 50, 45, 400, 2000 };
while (letter == 'Y')
{
string mystr = "";
cout << "enter the product name you want to search : ";
cin >> mystr;
int n = mystr.length();
char char_array[n + 1];
strcpy(char_array, mystr.c_str());
bool flag = false;
for (int i = 0; i < 7; i++)
{
int m = productNames[i].length();
char char_arrayOrig[m + 1];
strcpy(char_arrayOrig, productNames[i].c_str());
if (strstr(char_arrayOrig, char_array) == NULL)
{
flag = false;
}
else
{
flag = true;
position = i;
break;
}
}
if (!flag)
{
cout <<
"entered product not found in the product list . Do you want to search again Y/N ? : ";
cin >> letter;
}
I simply want the program to work and not stop because of errors, however, I want the results to be accurate.