I am having trouble finding out why user input is not showing up in the program after it is entered and the menu comes up. The program asks the user to input a product name then that product name is supposed to be the first option on the menu, however when the menu comes up it is blank. Can anyone tell me what I am doing wrong I am pretty sure it has to do with *newProduct in my code but I could be wrong and can't figure out the problem. Thanks for any help.
void displayProducts()
{
int total;
//array for quantity
int quantity[3];
int i;
for (i = 0;i < 3; i++)
quantity[i] = 0;
char selection = 'a';
//trying to dynamically allocate memory for products array while for the first element
//in the array having the user input the first item name and dynamically allocating
//that element based upon the size of the name the user imputs
string products[3];
string *productsPtr = new string[3];
for (int i=0; i<3;i++)
{
productsPtr[i] = products[i];
}
string uInpt;
string temp;
cout << "enter the first product name" << endl;
cin >> temp;
int len = temp.length() + 1;
string *newProduct = new string[len];
temp = *newProduct;
products[0] = *newProduct;
products[1] = "oranges";
products[2] = "bananas";
cout << "you entered " << products[0] << endl;
cout << "Press 4 to proceed to order summary." << endl << endl;
cout << "Enter selection: ";
// read user selection
do
{
cout << "The list of products are below" << endl;
cout << "product 1:" << products[0] << endl;
cout << "product 2:" << products[1] << endl;
cout << "product 3:" << products[2] << endl;
cin >> selection;
// program crashes when entering quantity?
switch (selection)
{
case'1':
cout << "You selected - " << products[0] << endl;
cout << "Please enter quantity. ";
cin >> quantity[0];
break;
case'2':
cout << "You selected - oranges" << endl;
cout << "Please enter quantity. ";
cin >> quantity[1];
break;
case'3':
cout << "You selected - bananas" << endl;
cout << "Please enter quantity. ";
cin >> quantity[2];
break;
case'4':
cout << "Thank you." << endl;
break;
//if 1, 2, 3 or 4 is not selected then go to the default case
default: cout << "Invalid selection. Please try again";
// no break in the default case
}
cout << endl << endl;
}
while (selection != '4');
cout << "\nYou ordered " << quantity[0] << products[0] << " for a cost of $" << quantity[0] << endl;
cout << "You ordered " << quantity[1] << " oranges" << " for a cost of $" << quantity[1] << endl;
cout << "You ordered " << quantity[2] << " bananas" << " for a cost of $" << quantity[2] << endl;
//using the quantity array to calculate total
total = (quantity[0] + quantity[1] + quantity[2]);
cout << "Your grand total is $" << total << endl;
cin.get();
}