|
-
October 31st, 2010, 07:27 PM
#4
Re: Extracting a line from content in the line
A vector is similar to an array, except that is grows dynamically. You don't need to know in advance exactly how many elements the vector will hold. Whenever you need to add an element to the vector, you just use the member function push_back().
The simpler (and more limited) option would be to just use an array. Of course the size must be fixed and it does not grow dynamically:
Book library[50];
Obviously in this case there can only be a maximum of 50 books in the library. If you want to read more about vectors, click here.
You will want to use a loop to bring the user back to the menu. Here is an example of this that I used in an earlier posting:
Code:
int main () {
string s;
do {
cout << "What would you like today?" << endl;
cin >> s;
switch(toupper(s[0])){
case 'W':
cout << "What is the amount?" << endl;
//etc
break;
case 'Q':
cout << "Goodbye";
return 0;
default:
cout << "Invalid selection. Please try again." << endl;
break;
};
}
while(cin);
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|