Hello, I'd first like to introduce myself to these forums as I will most likely spend lots of time here in the future. I'm Bruno Gavranovic, aka bgavran3, I'm 14 years old and I'm pretty familiar with modding, I'm working as a level designer on 2 game modifications but I'd like to move on to more complex things, such as coding, since mapping is quite easy, anyone can do that.
So, I've started learning C++, I pretty much learnt the basics and now I started working on some a bit more complex project.
What I want is to get input from the user and if the input is equal to one of the words, the program responds with a text, if its not, it responds with another text.
So the user, for example types in "hi" and the program checks if the text he typed is equal to words "hey" or "hello" or "hi". If it is, program greets him with "Hello", if the text he typed isn't equal to one of those, program responds with "What?"
Code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
char input[15];
char answer[15];
struct database {
char greets;
}
database beg;
beg.greets = "hi" && "hey";
cin.getline (input, 15, '\n');
answer[0]='\0';
strcat (answer, beg.greets);
if (strcmp (input, answer) == 0)
cout<<"Hello";
else
cout<<"What?";
cin.get();
}
But the code isn't working for some reason or another, here are list of errors CodeBlocks compiler shows to me:
Code:
error: 'database' does not name a type
error: 'beg' was not declared in this scope
I know its doable and easier using strings, by comparing string A (hi) with string B (hey), if they're not equal then comparing string A (hi) with string C (hello) and then print out the response based on this but at some point in the program development I will need to have lots of words input needs to be compared with and I want to find a way in which I'll just have to add one more word to the list to make it work.
I'm using structures at the moment but I'm not sure are they the best way... if not, can someone point me in the right direction?
And one more question, what is the best way to store unlimited amount of words? What I need is to get the input from the player, display an text, get the input from the player, display an text, get the input...
And each time I want to be able to check what exactly input is, what the user has typed.
Thanks