This problem was from the book C++ Primer Plus Chapter 4 #8. The point of the code is to create a structure and use the new keyword to dynamically create a new structure. This problem makes me alter my code for the previous problem in the book so that I must enter the diameter before the name. However, getline(cin, p->name) does not work for me for some reason even though it did when I asked for the name before the diameter. It just asks for the diameter and after I enter it, the program asks me for the weight right after. Does anyone know the problem? Thank you!
#include <iostream>
using namespace std;
struct pizza
{
string name;
int diameter;
double weight;
};
int main()
{
pizza *p = new pizza;
cout << "Enter diameter: ";
cin >> p->diameter;
cout << "Enter name of the company: ";
getline(cin, p->name);
cout << "Enter weight: ";
cin >> p->weight;
cout << p->name << endl << p->diameter << endl << p->weight << endl;
return 0;
}