
May 14th, 2005, 10:13 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 1
Time spent in forums: 13 m 39 sec
Reputation Power: 0
|
|
Help w/ some code
Greetings, I keep looking.. but I cannot figure out why this isn't working..
Code:
// Game titles
// CH4 exercise (using vectors and iterators)
// The purpose of this program is to allow the user
// the ability to create a list of their game titles,
// by adding elements to a vector, and removing them.
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
vector<string> titles; // Vector for titles
vector<string>::iterator eVal; // Iterator used to edit data
vector<string>::const_iterator dVal; // Iterator used to view data
while (true)
{
int choice = 0; // Menu options selector
char option; // Return to Menu option
cout << "\t\t\nWelcome to the Game titles Main Menu\n";
cout << "Please select your option.\n";
cout << "\t1 - View titles\n";
cout << "\t2 - Add a title\n";
cout << "\t3 - Remove a title\n";
cout << "\t4 - Exit\n";
cout << "Choice: ";
cin >> choice;
if (choice == 1)
{
cout << "\nYou have " << titles.size() << " games:\n";
for (dVal = titles.begin(); dVal != titles.end(); ++dVal)
cout << *dVal << endl;
continue;
}
while (choice == 2)
{
string input; // Title input
cout << "\nEnter the title to add: ";
getline(cin, input, '\n');
titles.insert(titles.begin(), input);
for (dVal = titles.begin(); dVal != titles.end(); ++dVal)
cout << *dVal << endl;
cout << "Enter another title? [y,n]: ";
cin >> option;
if (option == 'y')
continue;
else
break;
}
}
}
this is obviously unfinished but the purpose so far is to be able to enter a title, and display the content of the vector.. I can only use vectors for this assignment, so please don't tell me to use linked lists  !
What happens is that when i enter 2 as the option, it displays "enter the game title" then jumps right to the "Enter another title" blurb.. my friend told me about getline, so i'm not sure if i'm using it properly .. because i don't even get input as a user.. it just skips it.
Thanks for any insight into the problem .. (i get no compile errors/ warnings.. so i guess it's a logical error.)
Thank you,
Alan
|