errors????????

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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 << "" ;
}
}

it is giving 5 errors in line 64
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
Last edited on
Pasting the errors will help us slightly. But if I had to guess, you need to have proper closing brackets
}
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.
Last edited on
understood. but it is still giving me 5 errors on line 63. here is my code ill post the errors under the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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
Last edited on
closed account (zb0S216C)
while (echp > 0); // This is in the wrong place. This should be after the closing brace of the do loop.

Last edited on
thanx alot it finally compiles but it doesnt work right... whenever i hit a it doesnt do anything and it is the same for b and backspase doesnt work
any help or tips are apreciated
closed account (zb0S216C)
a and b have not been initialized. You need to initialize them before you can use them.
what does initialize mean?????????
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.

-Albatross
Last edited on
o okey-dokey
Topic archived. No new replies allowed.