Hi everyone this is my first post and it would be great if someone could help me out. Im currently learning c++ from a book and im stuck on an exercise, the code i create doesnt result in a fully functioning program.

There are two problems, first i create a struct and dynamically create an array of "so many" of that struct. However when i access the objects in the array i begin referring to its elements from 1 not 0, does that seem correct to you?

The other problem is the cin function call is skipped during the for loop and the possible solution is perplexing me. Here is the code -

Code:
#include <iostream> 
/* This program should request the make and model year of a car, then
print out the results */

const int ArSize = 10;

struct car { 
       char car_make;
       int model_year;      
};

int main()
{
    using namespace std;
    int car_num;
    cout << "How many cars do you wish to catalogue? ";
    cin >> car_num;
    car * car_array = new car[car_num];
    
    for (int i = 1; i <= car_num; i++)
    {
           cout << "Car #" << i << ":" << endl;
           cout << "Please enter the make: ";
           cin.get(car_array[i].car_make);
           cout << "\nPlease enter the year made: "; 
           cin >> car_array[i].model_year;
           cout << endl << endl;
    }
    
    for (int i = 1; i <= car_num; i++)
    {
        cout << "\nThe make of car " << i << " is: " << car_array[i].car_make; 
        cout << "The year of car " << i << " is: " << car_array[i].model_year;
        cout << endl;
    }
    return 0; 
}

Last edited by shabbir; 25Jun2011 at 14:45.. Reason: Code blocks