my problem is that my program does not read the values that I entered from the keyboard, only reads the 1st, 2nd and last. I tried cin.ignore (); and other solutions, but do not work.
This is the input:
Insurance 1
Model: mazda
serial number: 60
Price: 9999
Contract number: 76Z
Contract money: 12
// after all characters, was \ n enter.
This is the conclusion:
Insurance 1
Model: mazda
serial number: 60
Price: 0
Contract number:
Contract money: 12
Here I write only a function, not the whole program:
struct tseg{
char model[15];
char serialnumber[15];
double price;
char contractnumber[15];
double contractmoney;
};
bool registrarSeguro(tconces *a, int p, int total){
a[p].contrato = new tseg[a[p].numSegurosActuales];
cout << "Enter model: " <<endl;
cin.ignore();
cin.getline(a[p].contrato[a[p].numSegurosActuales].model, 15);
cout << "Enter serial number: " <<endl;
cin.ignore();
cin.getline(a[p].contrato[a[p].numSegurosActuales].serialnumber, 15);
cout << "Enter price: " <<endl;
cin.ignore();
cin >> a[p].contrato[a[p].numSegurosActuales].price;
cout << "Enter contract number: " <<endl;
cin.ignore();
cin.getline(a[p].contrato[a[p].numSegurosActuales].numContrato, 15);
cout << "Enter contract number: " <<endl;
cin >> a[p].contrato[a[p].numSegurosActuales].impContrato;
a[p].numSegurosActuales++;
sw = true;
return (sw);
}
source
share