Start New Discussion within our Software Development Community

I was starting a cash register program. I got to the point of a simple test. I ran into a problem where when running the loop to input my variables, it completely blows through the loop the first time. I looks like this:

Product: Product: ---------now I could input

#include <iostream>
#include <new>
#include <fstream>
#include <string>





using namespace std;

int main ()
{

  int total_product_number;
  int current_product;
  
  string * product_name;
  double * product_price;
  
  
  product_name = new string[current_product];
  product_price = new double[current_product];
  
  
  
  
  ofstream sales;
  sales.open ("sales.txt", ios::app);
  
  ifstream prices;
  prices.open("prices.txt", ios::in);

  
  
  
  cout << "How many products would you like to buy? ";
  cin >> total_product_number;

  

  for (current_product=0; current_product<total_product_number; current_product++)
     {
         cout << "Product: ";
         // problem
         getline(cin, product_name[current_product]); // having problems
         // problem
     }
    
  system("CLS");
  
  
  cout << "You have entered: " << '\n';
  
  for (current_product=0; current_product<total_product_number; current_product++)
    {
      cout << product_name[current_product] << '\n';
      sales << product_name[current_product] << '\n';  
    }
    
    delete[] product_name;
    
    
    
  sales.close(); 
  prices.close();

  cin.ignore(2);
  
  return 0;
}

any help/explanation would be great.

This question has already been answered. Start a new discussion instead.