ey, i have started with c++ a couple of days ago, when i was now trying out the start of a rpg battle system i get 2 errors, first time i tryed i got 6 errors, but figured out 4 of them. The 2 last however i can't figure out, been looking through it a couple of hours and tryed searching etc, but nothing. So this is my last resort:P
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
int a, b;
int health;
a = 50;
b = rand()%100+1;
health = a - b;
cout << "Goblin hits you for" << b << "damage!\n";
if (health < 0)
cout << "you take" << b << " damage and die!\n";
if (health > 0)
cout << "you take" << b << "damage and have" << health << " health left!\n";
return 0;
}
The 2 errors:
(15) : error C2146: syntax error : missing ';' before identifier 'cin'
(19) : error C2447: '{' : missing function header (old-style formal list?)
Confusion here. cin does not even turn up in the code you have posted. Can you recheck??
If you are absolutely sure that the code you have posted is the only code in that particular file - then check that there isn't a second file being compiled that you have missed.
hmm, ye, somehow it mixed up with another code or something, started a new project and it work, sigh... alot of wasted time:P. but how do i make it so i have to click enter for each line? and also, somehow the goblin always does 42 damage :\
is it possible to add an "if" like if the health remaining is over 1 but under 10, i tryed this: if (health5>1<10). but that didn't work. I just ended adding an if for every letter from 1-9. But there has to be an easier way. sorry if i ask to much. you guys have really helped me out alot allready:D
this is the final result for this test:) will be trying to add so you can have different types of attacks, and hopefully get it to work without asking here^^
#include <iostream>
#include <ctime>
usingnamespace std;
int main ()
{
int a, b, c, d, e, f, g;
int health1;
int health2;
int health3;
int health4;
int health5;
a=100;
c=50;
srand(time(0));
b=rand()%15;
d=rand()%10;
e=rand()%30;
f=rand()%10;
g=rand()%50;
health1= a-d;
health2= c-b;
health3= health1-f;
health4= health2-e;
health5= health4-g;
cout << "A goblin appears out of nowhere and slices at you dealing " << d << " damage! You have " << health1 << " health left.\n" << endl;
cout << endl;
cout << "After recovering from the strike you rush towards the goblin inflicting\n " << b << " damage! The goblin now have " << health2 << " health left.\n" << endl;
cout << endl;
cout << "The goblin is quick to return the favor and claw you for " << f << " damage! you now have " << health3 << " health left.\n" << endl;
cout << endl;
cout << "You finally get the chance to draw your sword and cut the goblin for " << e << " damage!\n Your strike makes a deep wound immoblizing the goblin and gives you the\n opportunity to strike again. The goblin have " << health4 << " health remaining\n" << endl;
cout << endl;
cout << "You swing your sword with massive force hoping to eliminate this scum once and\n for all, your strike lands and deal " << g << " damage!\n" << endl;
cout << endl;
if (health5 < 1)
cout << "When you open your eyes after that final blow, you see the lifeless body of the goblin covered inn blood. After taking a deep breath you continue your journey\n inn this forsaken land.";
if (health5 > 1 && health5 < 10)
cout << "The goblin falls to the ground, exhausted and wounded. You take your sword and\n plants it inn his chest to end his misery.";
if (health5 > 9 && health5 < 19)
cout << "Finally realising that he is no match against you, the goblin runs into the\n forest before you can react.";
if (health5 > 19)
cout << "You put to much strenght into your massive strike which throws you forward crushing your head\n into a rock. Then all goes black.....";
}
The \n in mid-sentance is so the words don't get cut when in full screen which im using:)
cout << "A goblin appears out of nowhere and slices at you dealing " << d << " damage! You have " << health1 << " health left.\n\nAfter recovering from the strike you rush towards the goblin inflicting\n " << b << " damage! The goblin now have " << health2 << " health left.\n\nThe goblin is quick to return the favor and claw you for " << f << " damage! you now have " << health3 << " health left.\n\nYou finally get the chance to draw your sword and cut the goblin for " << e << " damage!\n Your strike makes a deep wound immoblizing the goblin and gives you the\n opportunity to strike again. The goblin have " << health4 << " health remaining\n\nYou swing your sword with massive force hoping to eliminate this scum once and\n for all, your strike lands and deal " << g << " damage!\n\n;