Text Based Game Code has 45 Errors in VC++
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
// ===ints===
int gold = 100;
int lvl;
int strength;
int agility;
int intelligence;
int HP;
int MP;
int ItemID[];
int MonsterID[];
int attack;
int defense;
int Maxlvl = 99;
// ===floats===
float XP;
//===strings===
string MonsterName[];
string ItemName[];
const string GameName = "Templar Knights";
string Options;
//===bool===
bool GameStartMenu = true;
bool MainGame = false;
// Seting up WaitSec()
inline void WaitSec(int seconds)
{
Sleep(seconds * 1000);
}
int main ()
{
WaitSec(1);
cout << "_-*^*-_Welcome to " << GameName << "_-*^*-_";
WaitSec(3);
cout << "\n\nChoose One of the following options:\n\n";
WaitSec(2);
cout << "New Game\nExit\n\n";
cin << Options;
if (Options == "New Game"){
cout << "Loading...";
GameStartMenu = false;
}
if (Options == "Exit"){
return 0;
}
if (Options != "New Game" && Options != "Exit"){
cout << "Please Enter only New Game or Exit";
return 0;
}
return 0;
}
This code is showing 45 errors when it tries to compile in VC++. Its not done by a long shot and its very insufficient, I know. If anyone can tell me whats gone wrong and explain it to me so I don't mess up this dramatically again it would be appreciated.
1. wrap your code in [ source ] and [ /source ] tags (take out the spaces).
2. when posting about errors it's good to post at least the first 2-3 errors.
3. i hope very much that you're using a book to help you learn c/c++?
4. off the top of my head the things i notice are you're making some arrays of undefined size - c++ can't do this with statically allocated data. you probably want a std::vector<std::string> or std::vector<std::int>
int ItemID[];
int MonsterID[];
or if you know their sizes int ItemID[size];
your std::cin line cin << Options; should be cin >> Options;
not sure if i see anything else, but i really very strongly suggest you get a book to teach you c++ (like C++ Primer or C++ Primer Plus (my favorite)).
good luck
2. when posting about errors it's good to post at least the first 2-3 errors.
3. i hope very much that you're using a book to help you learn c/c++?
4. off the top of my head the things i notice are you're making some arrays of undefined size - c++ can't do this with statically allocated data. you probably want a std::vector<std::string> or std::vector<std::int>
int ItemID[];
int MonsterID[];
or if you know their sizes int ItemID[size];
your std::cin line cin << Options; should be cin >> Options;
not sure if i see anything else, but i really very strongly suggest you get a book to teach you c++ (like C++ Primer or C++ Primer Plus (my favorite)).
good luck
I've also noticed that you have variables declared but not set. You should make it a practice to set everything you declare, even to 0.
For example:
int lvl;
To:
int lvl = 0;
The reason you should make this a habit is due to pointers. You don't want pointers sitting around without being pointed to something or being NULL.
For example:
int lvl;
To:
int lvl = 0;
The reason you should make this a habit is due to pointers. You don't want pointers sitting around without being pointed to something or being NULL.
Practice writing less code at a time. Only add a variable for "strength", for example, when you are ready to write the code that will use it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement