I am a novice programmer and I am creating a program that holds several objects of a struct type. The program needs to accept user input but I don't know how to do it. First, here's the code I'm using to define the struct:
struct Apartment{
int number;
string owner;
string condition;
}ap;
And here's the code I'm using to ask for user input:
cout << "Enter the apartment number: " << endl;
cin >> ap.number;
cout << "Enter the name of the owner: " << endl;
cin >> ap.owner;
cout << "Enter the condition: " << endl;
cin >> ap.condition;
apartment building[50] = { ap.number, ap.owner, ap.condition};
The last line of code is how I am trying to save the object in an array, bu I don't know if it works. I later need to print all the objects, so it would be nice if you helped me with that too. I am using Visual Studio 2013 as a compiler, in case it makes any difference.
See Question&Answers more detail:os