hi i "borrowed" this code from someone else. i just saw it and liked it so i am trying to add onto it like i want but this first part is killin me i have been through the code and i cant find what to do please help.
#include <iostream>
#include <windows.h>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::numeric_limits;
using std::streamsize;
int main()
{
system("TITLE TEXTVENTURE!!");
string name;
int echp, emhp, dmg;
char choice;
cout << "\t\t--WELCOME TO TEXTVENTURE--\n";
cout << "Hello. What is your name?\n";
cin >> name;
cout << "So your name is " << name << "now is it \n";
cout << "Hello, and welcome, " << name << ", you are about to enter the world";
cout << " of Textventure.";
cout << "\nYou make selections on what you do by typing any number option given.\n";
cout << "Typing something other than the options given will bring up an error.\n";
cout << "You have health. You may be damaged by monsters, or the result of \n";
cout << "another choice you made. You will encounter monsters and must fight.\n";
cout << "When you fight, or complete other special encounters, you will earn ap,\n";
cout << " aka adventure points, which can make you level up and up your stats.\n";
cout << "There are other ways to raise your stats, anyways, good luck!\n";
cout << "Did you get that? ^^ ";
system("PAUSE");
//JAIL CELL//
cout << "\n\nYou awake in a jail cell.\n";
cout << "It's dark and you can only remember your name.\n";
cout << "In this room is only one cell, and a door out. Your cell is locked however.\n";
cout << "What would you like to do?\n";
cout << "a. Try and break the lock with your fists.\nb. Try and squeeze through the bars.\n";
echp = 5;
emhp = 5;
char a;
char b;
do
{
cin >> choice;
if (choice == a);
{
cout << "you inflict 2 damage " ;
echp = echp - 2;
}
if (choice == b);
{
cout << "you try and try but you cant get through" ;
}
while (echp > 0);
if (echp = 0);
{
cout << "yay you broke the lock" ;
system ("PAUSE");
return 0;
}
cout << "" ;
}
}
line 56 is wrong, it shouldn't have a semicolon on the end and you should be using the comparison operator (==) not the assignment operator (=).
What is the aim of the code after the return 0;? that will never run unless the for loop is skipped over, and I can't see the point in that, you should probably also be checking in that for loop for if (echp <= 0) as anything below zero will signify that it has been broken
You should also sort your indentation out it's messy, and try to declare your variables closer to where you use them, if you only use a variable inside of one loop, declare it inside of the loop, this means that if the for loop is never entered the variable doesn't need to be created, and it doesn't allow anything outside of the variable's scope to use it.
EDIT - Just noticed you have semicolons after all of your if statements, they need to be taken out too
thanx quirky username. i just got a couple of things to add. the reason i put that one thing after return 0 is when i did for whatever reason it took away like 3 errors. idk y. and i dont really know what you meant when you said
you should probably also be checking in that for loop for if (echp <= 0) as anything below zero will signify that it has been broken
echp is inititialised to 5, and in the body of one of your if statements you reduce it by 2, this means that it will never be 0, it will be 5, then 3, then 1, then -1. Checking that it is 0 or below is what you should be doing. The same would apply to attacking a monster which has for example, 5 health, and you do 10 damage, as long as its health is 0 or below then it is dead, you can't gaurantee that it's health will ever be 0.
#include <iostream>
#include <windows.h>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::numeric_limits;
using std::streamsize;
int main()
{
system("TITLE TEXTVENTURE!!");
string name;
int echp, emhp;
char choice;
cout << "\t\t--WELCOME TO TEXTVENTURE--\n";
cout << "Hello. What is your name?\n";
cin >> name;
cout << "So your name is " << name << "now is it \n";
cout << "Hello, and welcome, " << name << ", you are about to enter the world";
cout << " of Textventure.";
cout << "\nYou make selections on what you do by typing any number option given.\n";
cout << "Typing something other than the options given will bring up an error.\n";
cout << "You have health. You may be damaged by monsters, or the result of \n";
cout << "another choice you made. You will encounter monsters and must fight.\n";
cout << "When you fight, or complete other special encounters, you will earn ap,\n";
cout << " aka adventure points, which can make you level up and up your stats.\n";
cout << "There are other ways to raise your stats, anyways, good luck!\n";
cout << "Did you get that? ^^ ";
system("PAUSE");
//JAIL CELL//
cout << "\n\nYou awake in a jail cell.\n";
cout << "It's dark and you can only remember your name.\n";
cout << "In this room is only one cell, and a door out. Your cell is locked however.\n";
cout << "What would you like to do?\n";
cout << "a. Try and break the lock with your fists.\nb. Try and squeeze through the bars.\n";
echp = 5;
emhp = 5;
char a;
char b;
do
{
cin >> choice;
if (choice == a)
{
cout << "you inflict 2 damage " ;
echp = echp - 2;
}
if (choice == b)
{
cout << "you try and try but you cant get through" ;
}
while (echp > 0);
if (echp == 0)
{
cout << "yay you broke the lock" ;
system ("PAUSE");
return 0;
}
}
}
error 1: expected while before ; token
error 2: expected ( before ; token
error 3: expected primary expression before ; token
error 4: expected ) before ; token
error 5: expected ; before ; token
Initialize basically means setting your variables to something (usually with meaning, other times not) after you declare them as an initial value. Think: Initial-ize.