#include <iostream>
usingnamespace std;
struct cars
{
string make;
int year;
};
int main()
{
cout << "How many cars do you want to add?" << endl;
int howMany;
cin >> howMany;
int carNumber = 1;
cars * car = new cars[howMany];
for(int y = 0; y < howMany; y++)
{
cout << "\nCar #" << carNumber << endl;
cout << "\nPlease enter the make: " << endl;
getline(cin, car[y].make); //cin >> car[y].make; - 1 word
cout << "Please enter the year made: " << endl;
cin >> car[y].year;
cout << "\n" << endl;
carNumber++;
}
cout << "Here is your collection: " << endl;
for(int z = 0; z < howMany; z++)
{
cout << car[z].year << " " << car[z].make << endl;
}
cin.get();
cin.get();
return 0;
}
I do not have any error codes or anything, but when I launch the program it skips the "Please enter a year made" question as if there was already a blank value stored in the system for it.
I have used the getline function before but for some reason there is a problem
with me trying to use it to point to a a new structure value.
Any helpful advice is welcome, thanks!