Hello. I am trying to store information in a structure using this pointer loop method. If i try using the getline() method it seems to crash the program, and without it crashes if i enter more then 1 word.
Also when the last loop deleting the pointers goes off it crashes the program....Kinda confused why.
Help is appreciated :) Thanks
//Exc_6.cpp - practice with structures
#include<iostream>
#include<string>
using namespace std;
struct car
{
string make;
int year;
};
int main()
{
int input, i;
cout << "How many cars would you like to catalog? ";
cin >> input;
car ** numberOfCars;
numberOfCars = new car * [input];
for (i = 0; i <= input; i++)
{
numberOfCars[i] = new car;
cout << "Please enter the make: ";
cin >> numberOfCars[i]->make;
cout << "Please enter the year made: ";
cin >> numberOfCars[i]->year;
}
cout << "Here is your collection:" << endl;
for (i = 0; i <= input; i++)
{
cout << numberOfCars[i]->make << " " << numberOfCars[i]->year << endl;
}
for (i = 0; i <= input; i++)
{
delete numberOfCars[i];
}
delete [] numberOfCars;
system("PAUSE");
}