Jump to content

Featured Replies

Posted

I found this way back in the boards and tried to make it. when i put this in it said that it had an unexpected file end. can anyone help me fix this problem?

 

 

 

 

 

 

 


#pragma comment(lib, "winmm.lib")

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

const int goblo = 2;
const int gobhi = 6;
const int drglo = 8;
const int drghi = 18;
int player = 100;
int attack;
int gobattack;
int drgattack;
int bow = 9;
int axe = 12;
int gob = 25;
int drg = 60;
char name[50];
char tanswer[50];
char armanswer[50];
char answer[50];
char buyanswer[50];

int main(int argc, char* argv[])
{
PlaySound("wow_legends.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
time_t seconds;
cout<<"What's your name?"<<endl;
cout<<"***Max Name Size - 10***"<<endl;
cin.getline (name, 11);
cout<<"Welcome to my world, "<<name<<", what would you like to do?"<<endl;
cout<<"1--Talk to you.---"<<endl;
cout<<"2--Kill some monsters.---"<<endl;
cin.getline (answer, 50);
if(strcmp (answer, "1") == 0){    //First Drop --- To Talk
cout<<"What would you like to talk about, then?"<<endl;
cout<<"1--Where am I?---"<<endl;
cout<<"2--Is this a game?---"<<endl;
cin.getline (tanswer, 50);
if(strcmp (tanswer, "1") == 0)    //Second Drop --- To Where
cout<<"You're infront of your monitor talking to a C++ program."<<endl;
if(strcmp (tanswer, "2") == 0)    //Second Drop --- To IsGame
cout<<"I guess you could call this a text based game, yes."<<endl;
}
if(strcmp (answer, "2") == 0){    //First Drop --- To Buy
cout<<"Well, choose your weapon."<<endl;
cout<<"1--Sword - Damage is 4-10---"<<endl;
cout<<"2--Bow & Arrow - Damage 6-9---"<<endl;
cout<<"3--Axe - Damage 1-12---"<<endl;
cin.getline (buyanswer, 50);}
if(strcmp (buyanswer, "1") == 0){   //Second Drop --- To Swd
const int LOW = 4;
const int HIGH = 10;
time(&seconds);
srand((unsigned int) seconds);
cout<<"You got a Sword!"<<endl;
Sleep(3000);
cout<<"Lets fight our first monster now. Get your sword ready!"<<endl;
Sleep(3000);
cout<<"It's a goblin, hurry attack."<<endl;
while (gob > 0){	//Battle Loop
attack = rand() % (HIGH - LOW + 1) + LOW;
cout<<"***Slash***"<<endl;
Sleep(1000);
cout<<"The Goblin has "<<gob - attack<<" life left!"<<endl;
gob = gob - attack;
Sleep(1500);
gobattack = rand() % (gobhi - goblo +1) + goblo;
if(gob > 0){
cout<<"***Whack***"<<endl;
Sleep(1000);
cout<<"You have "<<player - gobattack<<" life left!"<<endl;
player = player - gobattack;
Sleep(1500);
}
}
if(gob <= 0){
cout<<"Congratulations, you killed the goblin."<<endl;
cout<<"Why don't you pick out some armor now?"<<endl;
cout<<"1--Leather Tunic - Protection 1---"<<endl;
cout<<"2--Chain Mail - Protection 2---"<<endl;
cout<<"3--Full Plate Mail - Protection 3---"<<endl;
cin.getline (armanswer, 50);
if(strcmp (armanswer, "1") == 0){	//Third Drop --- Sword and Tunic
cout<<"You got a Leather Tunic!"<<endl;
Sleep(3000);
cout<<"Oh no, you're under attack again. It looks like a Dragon!"<<endl;
Sleep(1500);
while (drg > 30 && player > 0){	//Battle Loop 2
attack = rand() % (HIGH - LOW + 1) + LOW;
cout<<"***Slash***"<<endl;
Sleep(1000);
cout<<"The Dragon has "<<drg - attack<<" life left!"<<endl;
Sleep(1500);
drg = drg - attack;
drgattack = rand() % (drghi - drglo +1) + drglo;
if(drg > 30){
cout<<"***Smash***"<<endl;
Sleep(1000);
cout<<"You have "<<player - drgattack + 1<<" life left!"<<endl;
player = player - drgattack;
Sleep(1500);
}
}
if(drg <= 30){
cout<<"Looks like it's running away!"<<endl;
Sleep(1500);
cout<<"I think it's time for you to go and rest, I'll talk to you some other time."<<endl;
}
if(player <= 0){
cout<<"You have fallen!"<<endl;
cout<<"G";
Sleep(500);
cout<<"a";
Sleep(500);
cout<<"m";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"O";
Sleep(500);
cout<<"v";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"r"<<endl;
}
}
if(strcmp (armanswer, "2") == 0){	//Third Drop --- Axe and Chain Mail
cout<<"You got a Chain Mail!"<<endl;
Sleep(3000);
cout<<"Oh no, you're under attack again. It looks like a Dragon!"<<endl;
Sleep(1500);
while (drg > 30 && player > 0){	//Battle Loop 2
attack = rand() % (HIGH - LOW + 1) + LOW;
cout<<"***Slash***"<<endl;
Sleep(1000);
cout<<"The Dragon has "<<drg - attack<<" life left!"<<endl;
Sleep(1500);
drg = drg - attack;
drgattack = rand() % (drghi - drglo +1) + drglo;
if(drg > 30){
cout<<"***Smash***"<<endl;
Sleep(1000);
cout<<"You have "<<player - drgattack + 2<<" life left!"<<endl;
player = player - drgattack;
Sleep(1500);
}
}
if(drg <= 30){
cout<<"Looks like it's running away!"<<endl;
Sleep(1500);
cout<<"I think it's time for you to go and rest, I'll talk to you some other time."<<endl;
}
if(player <= 0){
cout<<"You have fallen!"<<endl;
cout<<"G";
Sleep(500);
cout<<"a";
Sleep(500);
cout<<"m";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"O";
Sleep(500);
cout<<"v";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"r"<<endl;
}
}
if(strcmp (armanswer, "3") == 0){	//Third Drop --- Axe and Full Plate Mail
cout<<"You got a Full Plate Mail!"<<endl;
Sleep(3000);
cout<<"Oh no, you're under attack again. It looks like a Dragon!"<<endl;
Sleep(1500);
while (drg > 30 && player > 0){	//Battle Loop 2
attack = rand() % (HIGH - LOW + 1) + LOW;
cout<<"***Slash***"<<endl;
Sleep(1000);
cout<<"The Dragon has "<<drg - attack<<" life left!"<<endl;
Sleep(1500);
drg = drg - attack;
drgattack = rand() % (drghi - drglo +1) + drglo;
if(drg > 30){
cout<<"***Smash***"<<endl;
Sleep(1000);
cout<<"You have "<<player - drgattack + 3<<" life left!"<<endl;
player = player - drgattack;
Sleep(1500);
}
}
if(drg <= 30){
cout<<"Looks like it's running away!"<<endl;
Sleep(1500);
cout<<"I think it's time for you to go and rest, I'll talk to you some other time."<<endl;
}
if(player <= 0){
cout<<"You have fallen!"<<endl;
cout<<"G";
Sleep(500);
cout<<"a";
Sleep(500);
cout<<"m";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"O";
Sleep(500);
cout<<"v";
Sleep(500);
cout<<"e";
Sleep(500);
cout<<"r"<<endl;
return 0;
}
}
}
}

When there is an error like, "Unexpected end of file" or whatever, that usually means there is a close bracker ( } ) missing. I dunno though, I don't really feel like reading the code, give it a try though.
It's called indenting, so you know if you're missing a bracket or something..
  • Author
thatnks for the help. i got it to work. but now, after i ask tell the people that they are talking to a pc it goes to the while loop with the goblin
Guest
This topic is now closed to further replies.