Im currently in highschool, and in a C++ Programming Class
Before the end of the year we must creates a game, and I've been working on the project. We have yet to learn the void declaration (or whatever it is when you do this "void name()" instead of "int main()") so I've gone online to look up how these work. My problem is that when I run the program, it displays the void over and over (kind of flashing text) and won't respond to any user input, so I must stop debugging.
Here's the code of the two important parts
#include <iostream>
#include <string>
#include <stdio.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
//Global Vars
int mainMenuChoice = 0;
//voids
void options();
void mainMenu();
void startGame();
//inizialize main
int main()
{
mainMenu();
return 0;
}
Correct me if I'm wrong, but you don't actually ever ask for any input. >_>
Because the input variable is never set, it repeatedly enters into default (as the variable is 0), which clears the screen and re-displays the menu. This happens forever.
I would highly recommend using a loop for the menu instead of recursively calling mainMenu()...the way you have it written now, it will recurse infinitely until the program runs out of stack space and dies.
the problem occurs while the main menu screen displays, but yes Zhuge, I just saw i have no input, so im guessing th computer reads it and doesnt see any way the user can input so instantly chooses default for the user, bringing them back to the main menu. I cant fix it now but when im back on the right computer ill check it out. Thanks in advanced if this works