i'm fairly new to programming in C++ and i am stuck on something i am trying to create. it is a very simple program in which you type in a word and it searches for your word in a database within the program to tell you whether you have typed a word that is in the database or it isn't in the database.
for example, a band. I want it so when you type in a band it searches through a structure and when it finds it, prints out whatever their lead singers name is. here is where i am at and i don't know why it doesn't work.
PHP Code:
#include <iostream>
#include <string>
using namespace std;
void getSingerName(string x); /*function for putting a singer to a band*/
int main()
{
struct band{ /*set up the band names structure*/
string databaseBand;
};
band names[2];
names[0].databaseBand="metallica";
names[1].databaseBand="pantera";
const char total=20;
char typedInBand[total]; /* setting up variables for a cin.get() */
cout<<"Type in the band name\n";
cin.get(typedInBand, total).get(); /*get the band name*/
for (int loopIndex=0; typedInBand[total] != names[loopIndex]; loopIndex++)
{getSingerName();}
return 0;
}
void getSingerName(string typedInBand)
{
if (typedInBand = "metallica")
{ cout<<"james\n";}
else {cout<<"phil\n";}
}
is there any way to make an array or struct with strings and search throught them?
i really need help