valestrom 17 Junior Poster in Training

Pretty sure this would be the right area to post this, I recently started to make this program in Visual c++ 2010, and Before I added the GCF.h form, I had no errors at all. Now I get all these

1>------ Build started: Project: Valestroms Calculator, Configuration: Debug Win32 ------
1> Calclist.cpp
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2065: 'Calclist' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2061: syntax error : identifier 'Calclist'
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(140): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(140): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\GCF.h(182): error C2065: 'Calclist' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\GCF.h(182): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\GCF.h(182): error C2061: syntax error : identifier 'Calclist'
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\GCF.h(183): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\GCF.h(183): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> GCF.cpp
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2065: 'Calclist' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(139): error C2061: syntax error : identifier 'Calclist'
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms calculator\valestroms calculator\Form1.h(140): error C2065: 'form' : undeclared identifier
1>c:\users\blackmethod\documents\visual studio 2010\projects\valestroms …

valestrom 17 Junior Poster in Training

Thanks for that, I know I asked this question earlier sometime, just wanted to clarify as to why it wasn't working. Thanks again.

valestrom 17 Junior Poster in Training

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!" …
valestrom 17 Junior Poster in Training

It's your file. Define it any way you want.
Is "10" useful to you as a string?

No, so I'll google it and see what I come up with.

valestrom 17 Junior Poster in Training

Create a data file where each line defines the values for each monster. Then create a read function that reads the file. This way you can add and modify monsters any time you want and won't have to change the program.

So pretty much filestream for the file, and read it so if it says:

Name:Rat
Attack: 10
Defense: 10
Health: 20

I would get it to read each line specifically , and take the value after the colon? And store it under a string? Or what? If not a string

valestrom 17 Junior Poster in Training

I was looking for an easy way to define variables for random monster encounters in my game. I'm not sure how to define some without typing out 1000+ lines of code for like 25 monsters. What I was wondering if there was a way to make a config file, or a way to do it in the c++ code itself where I could just define the monster, and set the integer values for it's variables. So something like this, don't know the code, so I'll kinda just write it out. Something like this.

Worm {
damage = 10;
health = 20;
defense = 10;
}
Wolf {
damage = 25;
health = 30;
defense = 15;
}

Something like that would be greatly appreciated.
Bonus points for text editable config file!

valestrom 17 Junior Poster in Training

Perfect, so glad people like you exist in this community =D

valestrom 17 Junior Poster in Training

I have a main c++ file with all my integer values, then I have a seperate c++ file with my algorithms for my battle function. May seem like a simple question, but how do I get the values from my main c++ file and use them in the other one and visa versa? Code snippets welcome, and help would be graciously accepted.

valestrom 17 Junior Poster in Training

And I must have forgotten to copy the headers, sorry. But no stdafx.h was not one of them.

valestrom 17 Junior Poster in Training

Thanks. That's all I wanted to know, I had to no idea what the precompiled header was for it.

valestrom 17 Junior Poster in Training

Hi, I wrote part of a program in visual c++, but I use dev c++ at school, so I tried just copying my code:

char mainmenu[50];
char game[50];
int strength;
int intelligence;
int dexterity;
int health;
int mana;
int damage;
int defense;
int k;
int roll;
int experience;
int levelup;

int main () {
	HANDLE hConsole;
int k;
 
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

k = 3;
    
  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(10000);
	}

But I get errors saying hConsole is undefined
STD_OUTPUT_HANDLE undeclared
expected ; before hConsole
SetConsoleTextAttribute undeclared


And it goes on saying cout, cin, and everything are the same way. I have no idea what files have to be included into the project in dev-c++, as in visual they are already included, help would be great. Thanks ahead of time!

valestrom 17 Junior Poster in Training

Thanks, I'll try this tomorrow

valestrom 17 Junior Poster in Training

That may work, but all I was really asking for was to be able to sort a set of algorithms into one simple function that can be called with a few lines of code instead of retyping it. So in the function I could define how much damage is done, from specific integer values, then to use it all I would have to do is call a battle function every time I want a battle. So instead of writing

if (steps == 10)
//Insert battle algorithm here.

// I could do something like

if (steps == 10)
// some function to call a predefined "battle function"
valestrom 17 Junior Poster in Training

What I want to do is have a predefined battle function, I can code the function, all I need to know how to do is have the function sitting there, so when I call it, all it takes is one or two variables to set up and go. So every time I don't have to input damage calculators, defense algorithms etc.
Help would be greatly appreciated, thanks.

valestrom 17 Junior Poster in Training

Well thanks, you got it working. Thumbs up to you =D

valestrom 17 Junior Poster in Training

Can you give an example of how a case could replace the "if" statement and such?

valestrom 17 Junior Poster in Training

So i'm making this periodic table kinda program here mainly outta boredom. But I came across a problem, when I type in the name for the element, the program just closes. Any ideas on how to get it to work properly. Here's my current code.

#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;

char elementname[100];
char mainmenuyesno[20];
int consoletextcolour;
HANDLE hConsole;
int main () {

	consoletextcolour = 234;
	SetConsoleTextAttribute(hConsole, consoletextcolour);
	mainmenu:
	cout <<"Welcome to Valestrom's Periodic Table"<<endl;
	Sleep(5000);
	cout <<"Please report any problems to Blackmethod@gmx.com"<<endl;
	Sleep(7500);
	system("cls");
	cout <<"Valestrom's Periodic table. By Blackmethod and Valestrom"<<endl;
	cout <<"Press ENTER/RETURN to continue";
	cin.get();
	system("cls");
	cout <<"Valestrom's periodic table V1.0"<<endl;
	cout <<"Type the name of an element to get info on it: ";
	cin.getline(elementname, 100);



	if (elementname == "Lithium" || elementname == "Li")
		do {
		system("cls");
	cout <<"LITHIUM (Li): Atomic Weight: 6.941" <<endl;
	cout <<"Ionic Charge: +1, Melting Point: 180.54 C" <<endl;
	cout <<"Boiling Point: 1342 °C"<<endl;
	cout <<"Return to main menu? Yes/No: ";
	cin.getline (mainmenuyesno, 20);
	if (mainmenuyesno == "Yes")
		goto mainmenu;
	else 
		exit(1);
		} while (elementname == "Lithium" || elementname == "Li");
	
	
	
	if (elementname == "Hydrogen" || elementname == "H")
		do {
		
	system("cls");
	cout <<"HYDROGEN (H): Atomic Weight: 1.00794" <<endl;
	cout<<"Ionic Charge: +1 -1, Melting Point: -259.14 C" <<endl;
	cout<<"Boiling Point: -252.87 C"<<endl;
	cout <<"Return to main menu? Yes/No: ";
	cin.getline (mainmenuyesno, 20);
	if (mainmenuyesno == "Yes")
		goto mainmenu;
	else 
		exit(1);
		} while (elementname == "Hydrogen" || elementname == "H");







end:
	return 0;
}
valestrom 17 Junior Poster in Training

So I tried deleting all the semicolons. But now when I type "new game" for a new game. Nothing happens. Just shows the text entry, then if I type it in again the program closes, ideas?

valestrom 17 Junior Poster in Training

Not sure what the exact title should be. But at a point in my text game. I want to have multiple selections. But whenever I put the code (shown below), compile the program, and run it I get this. It goes through my main menu, new game, all the stuff up to where you make the first decision in the game. Then instead of choosing one or the other, it runs through the first one. Then through the second. I'm stuck here and hoping somebody could enlighten me. Please don't say stuff like "Oooh your using this when you should be using thing" and chop through my code. Please just try to help me with the problem at hand.

Here is the entire source so far.

#include <iostream>
#include <Windows.h>
#include <stdlib.h>
using namespace std;

char startmenu[50];
char gamechoices[50];
int main()
	
{
  HANDLE  hConsole;
	int startmenucolour;
	int gamecolour;

	
  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  // you can loop k higher to see more color choices
  startmenucolour = 249;
  gamecolour = 240;
  {
    // pick the colorattribute k you want
    SetConsoleTextAttribute(hConsole, startmenucolour);
    cout << "Xelzia: Story of Kings" << endl;
  }
  cout << "New Game, Load Game, Quit Game, or About?";
  cin.getline (startmenu, 50);
 
  do {
	  system ("cls");
	  cout <<"You wish to load a game." <<endl;
	  cout <<"Since there is only 1 save slot I will now recall your most recent adventure" <<endl; //Unfinished!!

  }
  while (startmenu == "Load game" || startmenu == "Load");

  
  
  
  
  
  
  do {
	  system ("cls");
	  cout <<"You have chosen …