Reputation: 681
I'm new here!
I'm beginner in programing. Now I doing some exercises from my book and I have question - why in
cin.get(ps->volume);
show me error? Here's my whole code:
#include <iostream>
using namespace std;
struct inflatable //definicja struktury
{
char name[20];
float volume;
double price;
};
int main()
{
inflatable *ps = new inflatable; //alokacja pamieci na strukture, dynamiczne
cout << "Podaj nazwe dmuchanej zabawki: ";
cin.get(ps->name,20); //metoda pierwsza dostepu do pól
cout << "Podaj objetosc w centymetrach: ";
//cin >> (*ps).volume; //metoda druga dostepu do pól
cin.get(ps->volume);
cout << "Podaj cene (zl): ";
cin >> ps->price;
cout << "Nazwa: " << (*ps).name << endl;
cout << "Objetosc: " << ps->volume << " centymetrow." << endl; //metoda 1
cout << "Cena: " << ps->price << " zl." << endl; //metoda 1
delete ps;
return 0;
}
I know this line is good
//cin >> (*ps).volume; //metoda druga dostepu do pól
But I want to understand why I can't use line at the beginning of my post.
Upvotes: 0
Views: 708
Reputation: 66
Well, cin.get() is used for characters. The volume declared there is a float so it should be:
cin>>ps->volume;
Upvotes: 1