0
typedef struct car_description{
char car_name [MAXLEN];
int car_date;
}CAR;

int main() {
using namespace std;
int num_of_cars;
CAR users_car;

//ptr = new(CAR);
cout << "How many cars do you wish to catalog? ";
cin >> num_of_cars;
cout << "Please enter the make: ";
cin.get(users_car.car_name, MAXLEN);
cout << "Please Enter the year made: ";
cin >> users_car.car_date;

cout << "Here your collection:" << endl;
cout << users_car.car_date << " " << users_car.car_name;

}

When entering the first input skips over and ends the program. Tried to use different functions of cin like cin.get or getline and still the same issue. What is the issue with the code. (Probably a lot)

  • At least one problem I can see, but for full disclosure you should post the definition of `CAR`. – john Jan 09 '23 at 19:06
  • Well the duplicate addresses the problem I was seeing, but I suspect you have a second problem even after the first is fixed, so post the definition of `CAR`. – john Jan 09 '23 at 19:08
  • `get` is slightly different from `getline`. [Read the documentation](https://en.cppreference.com/w/cpp/io/basic_istream/get) to see what the differences are. – user4581301 Jan 09 '23 at 19:15
  • I just edited the post should include the struct – Alex Fridman Jan 09 '23 at 19:27
  • Side note: C++ learned a lot while evolving from C. One of the things is it knows darn well that `car_description` is a `struct` and doesn't need the `typedef` trick. `struct CAR { ... };` is all you need to write. – user4581301 Jan 09 '23 at 19:30

0 Answers0