|
||||||||||
|
|
#1 (permalink) |
|
Googler
![]() Join Date: Dec 2008
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
bin search
doesnt really work man. beeping is cazy
//Hero's Inventory Program #include<iostream.h> using namespace std; void PrintList(int numItems, string inventory[10]); //void search_binary(string dinventory[10], int hi, int low, string search_term); int main() { const int MAXITEMS=10; string inventory[MAXITEMS]; string dinventory[MAXITEMS]; int numItems=0; int dnumItems=0; cout<<"Hero's Inventory:"<<endl; inventory[0]="Lightsaber"; numItems=numItems+1; inventory[1]="Aluminum Trash Can"; numItems=numItems+1; inventory[2]="Trash Can Lid"; numItems=numItems+1; inventory[3]="Bazooka"; numItems=numItems+1; inventory[4]="Hoverboard"; numItems=numItems+1; inventory[5]="Catapult"; numItems=numItems+1; inventory[6]="Slingshot"; numItems=numItems+1; inventory[7]="Bastilla"; numItems=numItems+1; inventory[8]="Zombie Tooth"; numItems=numItems+1; inventory[9]="Soccer Ball"; numItems=numItems+1; for(int i=0;i<numItems;i++) cout<<inventory[i]<<endl; cout<<"\n You find a healing potion\n\n"; if(numItems<MAXITEMS) { inventory[3]="Healing Potion"; numItems=numItems+1; } else cout<<"You have too many items and cannot carry another."; cout<<endl; cout<<endl; cout<<"-------------------------------------------"<<endl; cout<<endl; cout<<endl; PrintList(numItems, inventory); cout<<endl; cout<<endl; cout<<endl; cout<<endl; cout<<"Druid's Inventory:"<<endl; dinventory[0]="Tome of Summoning."; dnumItems=dnumItems+1; dinventory[1]="Iron Dagger"; dnumItems=dnumItems+1; dinventory[2]="Light Robes"; dnumItems=dnumItems+1; dinventory[3]="Hood"; dnumItems=dnumItems+1; dinventory[4]="Eye of the Tiger"; dnumItems=dnumItems+1; dinventory[5]="Dagger"; dnumItems=dnumItems+1; dinventory[6]="Red Potion"; dnumItems=dnumItems+1; dinventory[7]="Blue Potion"; dnumItems=dnumItems+1; dinventory[8]="Green Potion"; dnumItems=dnumItems+1; dinventory[9]="Stick"; dnumItems=dnumItems+1; for(int i=0;i<dnumItems;i++) cout<<dinventory[i]<<endl; cout<<endl; cout<<endl; //When more then 10 Items are entered, the program crashes. It cannot hold more then 10 //Items, because it is set to hold ten and only ten. cout<<"\n You find a healing potion\n\n"; if(dnumItems<MAXITEMS) { dinventory[3]="Healing Potion"; dnumItems=dnumItems+1; } else cout<<"You have too many items and cannot carry another."; cout<<endl; cout<<endl; cout<<"-------------------------------------------"<<endl; cout<<endl; //string search_term; //cout<<"What would you like to search for in the druid's inventory?:"; //cin>>search_term; //search_binary(dinventory, 0, 9, search_term); cout<<endl; return 0; } void PrintList(int numItems, string inventory[10]) { string temp; int j; int i; cout<<"Your items:\n"; for(int i=0;i<numItems;i++) for(i=0;i<numItems;i++) { for (j=i+1;j<=numItems-1;j++) { if(inventory[i] > inventory[j]) { temp=inventory[i]; inventory[i]=inventory[j]; inventory[j]=temp; } } } cout<<endl; cout<<endl; for(i=0;i<=numItems;i++) cout<<inventory[i]<<endl; cout<<endl; cout<<"The current number of items in your inventory is "<<numItems<<endl; } /* void search_binary(string dinventory[10], int hi, int low, string search_term) { int search_pos=(low+hi)/2; while(dinventory[search_pos] != search_term && low <= hi) { if(dinventory[search_pos]>search_term) hi=search_pos-1; else low=search_pos+1; search_pos=(low+hi)/2; } if(low<=hi) cout<<"The"<<search_term<<" was found in the "<<search_pos+1<<" position"<<endl; else cout<<"The"<<search_term<<" was not found."<<endl; } */ /* For my reference-- string namelist[20]; string temp2; cout<<"How many names do you want to input? "; cin>>numvalues; for (i=0;i<numvalues;i++) { cout<<"Please enter a name: "<<endl; cin>>namelist[i]; } for(i=0;i<numvalues;i++) { for (j=i+1;j<=numvalues-1;j++) { if(namelist[i] > namelist[j]) { temp2=namelist[i]; namelist[i]=namelist[j]; namelist[j]=temp2; } } } cout<<endl; cout<<endl; for(i=0;i<=numvalues;i++) cout<<namelist[i]<<endl; */ |
|
|
|
|
Sponsored Links
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Google Revamps Search Results Landscape with Universal Search - Search Engine Roundtable | News Alerts | Google in the News | 0 | 05-17-2007 06:22 AM |
| Multiple Connections for Google Mobile Phone Search? - Search Engine Land | News Alerts | Google in the News | 0 | 03-21-2007 11:49 PM |
| Lenovo Dumping Google For Microsoft's Windows Live Search - Search Newz | News Alerts | Google in the News | 0 | 03-14-2007 03:38 PM |
| Google Video Search Now Include YouTube Results - Search Engine Land | News Alerts | Google in the News | 0 | 01-25-2007 08:02 AM |