• Advertisement
Sign in to follow this  

[C++] DOS Splash Screen

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone,    I am trying to write a C++ DOS program and right now I am just simply working on the Splash Screen. Well, when I try to get it to work, it doesn't. I press 4 to exit the game, and it just says "Thank you for playing Aevum of Bellum" and then starts a new line and shows the menu again, which it's not supposed to do, I think it's a problem in the while loop. Anyways, have a look. Main.cpp
#include <iostream>
#include <string>
#include <time.h>

#include "SplashScreen.h"

using namespace std;

int main()
{
	ShowSplash();

	cin.get();
	return 0;
}


SplashScreen.h
#ifndef SPLASHSCREEN_H
#define SPLASHSCREEN_H

void ShowSplash();

#endif


SplashScreen.cpp
#include <iostream>
#include <string>
#include <time.h>

#include "SplashScreen.h"

using namespace std;

// VARIABLES
int Splash_UserInput = 0;

// BOOLEANS
bool GameStarted = false;
bool LoadGame = false;
bool OptionsMenu = false;

void ShowSplash()
{
	while(GameStarted == false || LoadGame == false || OptionsMenu == false)
	{
		cout << "Welcome to Aevum of Bellum" << endl;
		cout << "==========================" << endl;
		cout << "1) New Game               " << endl;
		cout << "2) Load Game              " << endl;
		cout << "3) Options                " << endl;
		cout << "4) Exit                   " << endl;
		cout << "==========================" << endl;
		cout << "INPUT: ";

		cin >> Splash_UserInput;

		if(Splash_UserInput == 1)
		{
			system("CLS");
			GameStarted = true;
		}
		if(Splash_UserInput == 2)
		{
			system("CLS");
			LoadGame = true;
		}
		if(Splash_UserInput == 3)
		{
			system("CLS");
			OptionsMenu = true;
		}
		if(Splash_UserInput == 4)
		{
			system("CLS");
			cout << "Thank you for playing Aevum of Bellum!" << endl;
			cin.get();
		}
		if(Splash_UserInput <= 0 || Splash_UserInput >= 5)
		{
			system("CLS");
			cout << "INVALID USER INPUT" << endl;
			GameStarted = false;
			LoadGame = false;
			OptionsMenu = false;
			cin.get();
		}
	}
}


Share this post


Link to post
Share on other sites
Advertisement
Since you're using or's in the loop condition, it will only exit when all three of those booleans have been set to true. I'm guessing that wasn't your intention, perhaps you meant to use
while (GameStarted == false && LoadGame == false && OptionsMenu == false)

In which case it will break from the loop as soon as one of them is set to true. The code for Splash_UserInput == 4 doesn't affect the loop condition at all, so not sure why you were expecting it to break out from there.

You could also make that long sequence of if statements an if else block or a switch statement, eg.


if (Splash_UserInput == 1)
{
// do something here
}

else if (Splash_UserInput == 2)
{
// do something here
}


Then if the value is found to be 1 for example, the following if statements will be skipped as they are irrelevant (we already know it's not 2, 3, etc, so don't need to keep checking).

Share this post


Link to post
Share on other sites
Quote:
Original post by knowyourrole
Since you're using or's in the loop condition, it will only exit when all three of those booleans have been set to true. I'm guessing that wasn't your intention, perhaps you meant to use]


Ah, yes good catch on the loop, didn't even realize I did that. (/facepalm) . Thanks all for the help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement