I am writing a program in which you can ask a question, and then if the phrase is jknown to the computer, it will ouput an answer, but I was wondering is there a faster way to the way I am doing it, because at the moment i am just using a whole lot of ifs, which is quite a slow process.
Here is my code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include <tchar.h>
using namespace std;
int test()
{
cout << ":::";
return 0;
}
int main()
{
bool exit = false;
while(exit == false)
{
int pos = 11;
cout << "Welcome to Virtual Chat, ask any question you want .\n" << "(" << pos << ")";
int Keep = 1;
string Input;
while (Keep == 1)
{
getline(cin, Input);
if (Input.compare("b")==0 || Input.compare("B")==0 || Input.compare("B")==0)
{
cout << "Second Letter in the Alphabet\n Rhymes with 'Bee'";
test();
}
if (Input.compare("a")==0 || Input.compare("A")==0 || Input.compare("A")==0)
{
cout << "The first letter in the alphabet\n Vowel \n";
test();
}
if (Input.compare("Binary")==0 || Input.compare("binary")==0 || Input.compare("What is Binary?")==0)
{
cout << "Binary Code is the language of which computers use, using 0's and 1's\n";
test();
}
if (Input.compare("Why?")==0 || Input.compare("why")==0 || Input.compare("Why")==0)
{
cout << "Why what?\n";
test();
}
if (Input.compare("Do you hate me?")==0 || Input.compare("do you hate me")==0 || Input.compare("Do you hate me?")==0)
{
cout << "Hard to say\n";
test();
}
if (Input.compare("Do you like me?")==0 || Input.compare("do you like me")==0 || Input.compare("Do you like me?")==0)
{
cout << "Hard to say\n";
test();
}
if (Input.compare("Hello")==0 || Input.compare("hello")==0 || Input.compare("Hi")==0)
{
cout << "Hello!\n";
test();
}
if (Input.compare("What is your name?")==0 || Input.compare("what is your name?")==0 || Input.compare("What is your name")==0)
{
cout << "I am a computer, I do not have a Name\n";
test();
}
if (Input.compare("Where do you live?")==0 || Input.compare("where do you live?")==0 || Input.compare("Where do you live")==0)
{
cout << "I am a computer, I Live where you live\n";
test();
}
if (Input.compare("How old are you?")==0 || Input.compare("how old are you?")==0 || Input.compare("How old are you")==0)
{
cout << "I am a computer, I am not a human being\n";
test();
}
if (Input.compare("Are you smart?")==0 || Input.compare("are you smart?")==0 || Input.compare("Are you smart")==0)
{
cout << "No, I am not\n";
test();
}
if (Input.compare("Are you stupid?")==0 || Input.compare("are you stupid?")==0 || Input.compare("Are you stupid")==0)
{
cout << "Yes, I am\n";
test();
}
if (Input.compare("Why Are you stupid?")==0 || Input.compare("Why are you stupid?")==0 || Input.compare("Why Are you stupid")==0)
{
cout << "Because I am a computer\n";
test();
}
if (Input.compare("Help")==0 || Input.compare("help")==0 || Input.compare("Help!")==0)
{
cout << "\nType in a question or phrase, or even a word, and if it is stored in the program, a suitable asnwer or decription will be released.\nIf the input is not recognised by the computer, nothing will happen, and the computer will wait for the next input\n Current Commands: \n1)Help,help,Help! = Get Some help on using virtual chat.\n2)End = End Virtual Chat ";
test();
}
if (Input == "End") return 0;
}
continue;
}
char f;
cin >> f;
return 0;
}