Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 7th, 2004, 4:38 PM   #1
mason
Newbie
 
Join Date: Dec 2004
Posts: 6
Rep Power: 0 mason is on a distinguished road
Send a message via AIM to mason
so here is the source im doing as a weeekly assignment for my class(extra credit) and i gave it a shot and i couldnt seem a way to do it. here is my shot at it could u plz tell me errors and maybe a way to fix it

//Mason Dructor

#include <string>
#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

int main()
{

cout<<"\t\t\tGame Storage Pro\n\n";
cout<<"Welcome, what would you like to do?";
string input;
vector<string> library;
vector<string> gamename;
while(input != "quit")//main program loop
{
cout<<"\n\nIf you want to add a game to the list just type in 'add'.\n";
cout<<"To see your library type in 'library'.\n";
cout<<"To remove a game type in 'remove'.\n";
cout<<"To quit type in 'quit'\n";
cin>> input;
input = toupper(input);
cout<<"You chosed to "<<input.c_str<<".";

vector<string>::const_iterator iter;

if(input == "LIBRARY")
{
for(iter = library.begin(); iter != library.end(); ++iter)
cout << endl << endl << *iter << endl << endl;
}
string add;
if(input == "ADD")
{
cout<<"\n\nType the name of the game you would like to\n";
cout<<"your library.\n";
cin>>gamename;
gamename = toupper(gamename);
library.insert(library.begin(), gamename);
cout<<"You successfully added "<<gamename<<" to your library!\n\n";
}

if(input == "REMOVE")
{
cout<<"\n\nType the name of the game you want to remove.\n";
cin>>gamename;
gamename = toupper(gamename);
gamename.clear();
cout<<"\nYou successfully removed "<<gamename<<" from the library.";
}


return 0;
}
the assignment was to make a program that you can store game names, and view them and to remove them using vectors and iterators and such. like a stock program or sumthing
mason is offline   Reply With Quote
Old Dec 8th, 2004, 4:36 PM   #2
mason
Newbie
 
Join Date: Dec 2004
Posts: 6
Rep Power: 0 mason is on a distinguished road
Send a message via AIM to mason
ok i got one part,

gamename doesnt need to be vector, only library does

ne other tips
mason is offline   Reply With Quote
Old Dec 10th, 2004, 8:01 AM   #3
mason
Newbie
 
Join Date: Dec 2004
Posts: 6
Rep Power: 0 mason is on a distinguished road
Send a message via AIM to mason
ok i got it, just took a few mins looking at it


//Mason Dructor

#include <string>
#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

int main()
{

cout<<"\t\t\tGame Storage Pro\n\n";
cout<<"Welcome, what would you like to do?";
string input;
vector<string> library;
string gamename;
int i;
string add;
int number;
vector<string>::const_iterator iter;
while(input != "quit")//main program loop
{
cout<<"\n\nIf you want to add a game to the list just type in 'add'.\n";
cout<<"To see your library type in 'library'.\n";
cout<<"To remove a game type in 'remove'.\n";
cout<<"To quit type in 'quit'\n";
cin>>input;
cout<<"You chose "<<input.c_str()<<".";

if(input == "LIBRARY" || input == "Library" || input == "library")
{
for(iter = library.begin(); iter != library.end(); ++iter)
cout << endl << endl << *iter << endl;
}
if(input == "ADD" || input == "Add" || input == "add")
{
cout<<"\n\nType the name of the game you would like to add";
cout<<"your library.\nMake sure to make the game one word!\n";
cin>>gamename;
library.insert(library.begin(), gamename);
cout<<"You successfully added "<<gamename<<" to your library!\n\n";
}
if(input == "REMOVE" || input == "Remove" || input == "remove")
{
"/n/nType in the number of the game to remove it from the library.\n\n";

for(iter = library.begin(); iter != library.end(); ++iter)
cout<<endl<< *iter <<endl;

cout<<"\n";
cin>>number;
library.erase((library.begin() + number - 1));
cout<<"You succesfully removed " << library[number - 1]<<" from the library.";
}



}


return 0;
}
i could have made it better, but it got the job done so :dancing:
mason is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC