I have a function, kinda like a main menu. But no matter what it always picks the first statement, even if it doesn't match the parameters of it's if statement, so it nevers get to the exit game function. So I can't use my close game function, and I would like some help on how to fix it so that it will not just automatically pick the first statement.
Tldr: Main menu function is skipping else if statments and picking the first option.
Here's my code:
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <cstdlib>
#include "battle.h"
using namespace std;
extern char name[50];
char mainmenu[50];
char game[50];
extern int strength;
extern int intelligence;
extern int dexterity;
extern int health;
extern int mana;
extern int damage;
extern int defense;
int k;
extern int experience;
int levelup;
int main () {
HANDLE hConsole;
int k;
health = 20;
mana = 10;
strength = 5;
intelligence = 5;
dexterity = 5;
defense = 5;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
k = 12;
SetConsoleTextAttribute(hConsole, k);
cout <<"Main menu: New game, Load game, Exit game" <<endl;
cin.getline(mainmenu, 50);
if (mainmenu == "New" || "new" || "New Game" || "new game" || "New game" || "new Game" || "newgame" || "Newgame")
{
system("Cls");
cout <<"Hello, what may I call you by?" <<endl;
cin.getline (name, 50);
cout <<"Hello " <<name <<", and welcome to the world of Zelanthia." <<endl;
Sleep(1500);
cout <<"Our world has been horribly overrun with monsters, and we need you to help!" <<endl;
Sleep(2500);
cout <<"Here is a practice fight for you.";
Sleep(5000);
battleFunction();
}
else if (mainmenu == "Exit" || "exit" || "Exit Game" || "exit game" || "Exit game" || "exit Game" || "exitgame" || "Exitgame")
{
system("exit");
return 0;
}
return 0;
}