Original Post
Hello All, I am working through the C++ Primer Plus 5th Edition and I am having a slight problem with the following question:
I need a structure that takes the following information:
Pizza Company name
Diameter of the pizza
Weight of the pizza
The user needs to be able to enter the information and it has to be able to take more than one word answers for the pizza company name.
The line that i think is having the problem is the following:
cin.getline(ps.pizzaCompany, 20);
i had
cin << ps.pizzaCompany and it works with one word names but bugs out with two.
Now the problem that I am running into is that on the second pass through the loop it is printing the company name question and the diameter question without waiting for a response and I am not sure why.
I have the full code pasted below to help me find my problem...also let me know if anything should be done a different way or if it looks good the way it is.
Thanks,
Graig
I need a structure that takes the following information:
Pizza Company name
Diameter of the pizza
Weight of the pizza
The user needs to be able to enter the information and it has to be able to take more than one word answers for the pizza company name.
The line that i think is having the problem is the following:
cin.getline(ps.pizzaCompany, 20);
i had
cin << ps.pizzaCompany and it works with one word names but bugs out with two.
Now the problem that I am running into is that on the second pass through the loop it is printing the company name question and the diameter question without waiting for a response and I am not sure why.
I have the full code pasted below to help me find my problem...also let me know if anything should be done a different way or if it looks good the way it is.
Thanks,
Graig
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct PizzaAnalysis
{
char pizzaCompany[20];
int diameter;
int weight;
};
int main()
{
using namespace std;
PizzaAnalysis * ps = new PizzaAnalysis[3];
int i = 0;
while (i < 3)
{
cout << "what is the name of the pizza place? : " << endl ;
cin.getline(ps.pizzaCompany, 20);
cout << "What is the diameter of the pizza? : " << endl;
cin >> ps.diameter;
cout << "what is the weight of the pizza? : " << endl;
cin >> ps.weight;
i++;
}
i = 0;
while (i < 3)
{
cout << ps.pizzaCompany << endl;
cout << ps.diameter << endl;
cout << ps.weight << endl;
i++;
}
delete [] ps;
cin.get();
cin.get();
cin.get();
return 0;
}