#include <iostream.h>
#include <time.h>
#include <stdlib.h>
void main(void)
{
srand(unsigned(time(NULL)));
int dice;
float playerhealth;
playerhealth=100;
int movement;
movement=0;
int keyboard_check;
int gold;
gold=0;
char inventory1[]="Empty";
char inventory2[]="Empty";
char inventory3[]="Empty";
while (playerhealth>=0)
{
cout << "\nPress '1' to roll the die. ";
cout << "\nPress '2' to view your inventory. ";
cout << "\nPress '3' to visit the shop. ";
cin >> keyboard_check;
if (keyboard_check==1)
{
movement=movement++;
dice=rand() % 2;
if (dice==1)
{
cout << "\nYou have been attacked by an enemy!";
playerhealth=playerhealth - rand() % 6;
cout << "\nPlayer's health is: " << playerhealth;
if (playerhealth==0)
{
cout << "\nYou are dead!";
cout << "\nYou finished the game with: " << gold << "gold";
}
}
if (dice==0)
{
cout << "\nYou found a pot of gold!";
gold=gold + rand() % 11;
cout << "\nGold: " << gold;
}
}
if (keyboard_check==2)
{
cout << "\n" << inventory1;
cout << "\n" << inventory2;
cout << "\n" << inventory3;
}
if (keyboard_check==3)
{
cout << "\nPress '1' to buy a potion for 100 gold. ";
cin >> keyboard_check;
if (keyboard_check==1)
{
gold =gold;
inventory1[]="poiton";
}
}
}
}
In this code I get this error message "--------------------Configuration: Text Based RPG - Win32 Debug--------------------
Compiling...
Text Based RPG.cpp
C:\Documents and Settings\Admin\Desktop\Text Based RPG\Text Based RPG.cpp(59) : error C2059: syntax error : ']'
Error executing cl.exe.
Text Based RPG.exe - 1 error(s), 0 warning(s)"
Can someone please help? I am a beginner with C++, but I have used other very basic programming languages.
I am not quite sure on what I am doing with arrays i guess. I am going to re-read the chapter on arrays in the text book I've been using.
I thought with the array the way I'm using it, the number in the [] referred to the number of characters in the value. I'm kinda confused.