Jump to content
Psilvestre

not declared in this scope -.-

Recommended Posts

Psilvestre

Boas eu estou a fazer um desafio de c++, o objectivo e fazer um pequeno simulador de combate.

#include <iostream>
#include <stdlib.h>


using namespace std;

int welcome();
int game();
int lvlUp(int hp, int str, int dext, int lvl);

bool pot = false;

int main()
{
welcome();
return 0;
}
bool bChoice = false;
int welcome(){
do{
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "                                W  E  L  C  O  M  E     " <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "                                 Press a to Play." <<endl;
cout << "                                 Press b to Quit." <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;

char answer;
cin>>answer;




    switch(answer){

case 'a':
bChoice = false;
game();
break;

case 'b':
bChoice = false;
return 0;
break;

default:


bChoice=true;
break;
    }

}while(bChoice=true);




}

int game(){
string name;
bChoice=false;
do{
system ("CLS");
cout<<"Tell me your name:"<<endl;
cin>>name;

cout << "Ok, "<<name<<" Tell me your race:" << endl;
cout << "[H]Human"<<endl;
cout << "[T]Troll"<<endl;
cout << "[E]Elf"<<endl;
cout << "[D]Dwarf"<<endl;
char race;
cin>>race;

switch(race){
case 'h':
{
case 'H':
{
    int strenght = 20;
    int dex = 20;
    int health = 100;
    int exp = 0;
    int money = 600;
    int armor = 20;
    int level = 1;
    int expneed = level * 100;
    bChoice=false;
    break;
}
}
case 't':
{
case 'T':
{
    int strenght = 20;
    int dex = 20;
    int health = 200;
    int exp = 0;
    int money = 300;
    int armor = 20;
    int level = 1;
    int expneed = level * 100;
    bChoice=false;
    break;
}
}
case 'e':
{
case 'E':
{
    int strenght = 20;
    int dex = 40;
    int health = 100;
    int exp = 0;
    int money = 300;
    int armor = 20;
    int level = 1;
    int expneed = level * 100;
    bChoice=false;
    break;
}
}
case 'd':
{
case 'D':
{
    int strenght = 40;
    int dex = 20;
    int health = 100;
    int exp = 0;
    int money = 300;
    int armor = 20;
    int level = 1;
    int expneed = level * 100;
    bChoice=false;
    break;
}
}
    default:
    {
    bChoice=true;
    break;
    }

}
}while(bChoice==true);

cout<<"Ok..."<<name<<", "<<endl;

do{
int option;
cout <<"What do you want to do?"<<endl;
cout << "1.Go to the shop." <<endl;
cout << "2.See you stats." <<endl;
cout << "3.Go to Combat Zone." <<endl;
cout << "4.Quit" <<endl;

switch(option){
    case 1:
    {
     system ("CLS");
     int shopOption;
    cout << "Welcome to the shop." <<endl;
    cout << "What would you like to buy?" <<endl;
    cout << "1.Sword(200 G)" <<endl;
    cout << "2.Dagger(200 G)" <<endl;
    cout << "3.Shield(200 G)" <<endl;
    cout << "4.Leather Armor(150 G)"<<endl;
    cout << "5.Potion(150 G)" <<endl;
    cout << "6.Rare Candy(750 G)" <<endl;
    cin >> shopOption;

    switch(shopOption){
    case 1:
    {
        strenght = strenght + 20; // é aqui que se dá o erro
        break;
    }
    case 2:
    {

     strenght = strenght + 10;//e aqui
    dex= dex + 10;//e aqui
    break;
    }

    case 3:
    {
    armor=armor+20;//e aqui
    break;
    }
    case 4:
    {
        armor=armor+12;
        break;
    }
    case 5:
    {
        pot = true;
        break;
    }
    case 6:
    {
        lvlUp(health, strenght,dex,level);
        break;
    }
    default:
    {
        cout<<"not an option"<endl;
    }

}
}
    case 2:
    {
    int leaveStats
        system ("CLS");
        cout<<"Here are Your Stats:"<<endl;
        cout<<name<<":"<<endl;
        cout<<"Level:"<<level<<endl;
        cout<<"EXP:"<<exp<<"/"<<expneed<<endl;
        cout<<endl;
        cout<<"Health:"<<Health<<endl;
        cout<<"Strenght:"<<strenght<<endl;
        cout<<"Dexterety:"<<dex<<endl;
        cout<<"Armor:"<<armor<<endl;
        cout<<endl;
        cout<<"Gold:"<<money<<endl;
        cout<<endl;
        system ("Pause");
    }
}

}while(quit = false);


int lvlUp(int hp, int str, int dext, int lvl){
lvl=lvl+1;
hp=hp + (0.20*hp);
str=str + (0.20*str);
dext=dext + (0.20*dext);
return lvl;
return hp;
return str;
return dext;
}





}

Desculpem estar a por o código todo, mas eu achei melhor...

Na linha 197 é onde se da o erro, tem la um coment, o erro é: 'strenght' was not declared in this scope.

Alguem me pode ajudar?

Share this post


Link to post
Share on other sites
Andrepereira9

O teu problema é que estas a declarar as variáveis Armor, Strenght, .... dentro do Switch (race) Case. Tens de as declarar fora do Switch. E depois é so atribuires os valores

#include <iostream>
#include <stdlib.h>


using namespace std;

int welcome();
int game();
int lvlUp(int hp, int str, int dext, int lvl);

int strenght;
int dex;
int Health;
int exp;
int money;
int armor;
int level;
int expneed;

bool pot = false;

int main()
{
welcome();
return 0;
}
bool bChoice = false;
int welcome(){
do{
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "                                W  E  L  C  O  M  E     " <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "                                 Press a to Play." <<endl;
cout << "                                 Press b to Quit." <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;
cout << "" <<endl;

char answer;
cin>>answer;




    switch(answer){

case 'a':
bChoice = false;
game();
break;

case 'b':
bChoice = false;
return 0;
break;

default:


bChoice=true;
break;
    }

}while(bChoice=true);




}

int game(){
string name;
bChoice=false;
do{
system ("CLS");
cout<<"Tell me your name:"<<endl;
cin>>name;

cout << "Ok, "<<name<<" Tell me your race:" << endl;
cout << "[H]Human"<<endl;
cout << "[T]Troll"<<endl;
cout << "[E]Elf"<<endl;
cout << "[D]Dwarf"<<endl;
char race;
cin>>race;

switch(race){
case 'h':
{
case 'H':
{
    strenght = 20;
    dex = 20;
    health = 100;
    exp = 0;
    money = 600;
    armor = 20;
    level = 1;
    expneed = level * 100;
    bChoice=false;
    break;
}
}
case 't':
{
case 'T':
{
    strenght = 20;
    dex = 20;
    health = 200;
    exp = 0;
    money = 300;
    armor = 20;
    level = 1;
    expneed = level * 100;
    bChoice=false;
    break;
}
}
case 'e':
{
case 'E':
{
    strenght = 20;
    dex = 40;
    health = 100;
    exp = 0;
    money = 300;
    armor = 20;
    level = 1;
    expneed = level * 100;
    bChoice=false;
    break;
}
}
case 'd':
{
case 'D':
{
    strenght = 40;
    dex = 20;
    health = 100;
    exp = 0;
    money = 300;
    armor = 20;
    level = 1;
    expneed = level * 100;
    bChoice=false;
    break;
}
}
    default:
    {
    bChoice=true;
    break;
    }

}
}while(bChoice==true);

cout<<"Ok..."<<name<<", "<<endl;

do{
int option;
cout <<"What do you want to do?"<<endl;
cout << "1.Go to the shop." <<endl;
cout << "2.See you stats." <<endl;
cout << "3.Go to Combat Zone." <<endl;
cout << "4.Quit" <<endl;

switch(option){
    case 1:
    {
     system ("CLS");
     int shopOption;
    cout << "Welcome to the shop." <<endl;
    cout << "What would you like to buy?" <<endl;
    cout << "1.Sword(200 G)" <<endl;
    cout << "2.Dagger(200 G)" <<endl;
    cout << "3.Shield(200 G)" <<endl;
    cout << "4.Leather Armor(150 G)"<<endl;
    cout << "5.Potion(150 G)" <<endl;
    cout << "6.Rare Candy(750 G)" <<endl;
    cin >> shopOption;

    switch(shopOption){
    case 1:
    {
        strenght = strenght + 20; // é aqui que se dá o erro
        break;
    }
    case 2:
    {

     strenght = strenght + 10;//e aqui
    dex= dex + 10;//e aqui
    break;
    }

    case 3:
    {
    armor=armor+20;//e aqui
    break;
    }
    case 4:
    {
        armor=armor+12;
        break;
    }
    case 5:
    {
        pot = true;
        break;
    }
    case 6:
    {
        lvlUp(health, strenght,dex,level);
        break;
    }
    default:
    {
        cout<<"not an option"<endl;
    }

}
}
    case 2:
    {
    int leaveStats
        system ("CLS");
        cout<<"Here are Your Stats:"<<endl;
        cout<<name<<":"<<endl;
        cout<<"Level:"<<level<<endl;
        cout<<"EXP:"<<exp<<"/"<<expneed<<endl;
        cout<<endl;
        cout<<"Health:"<<Health<<endl;
        cout<<"Strenght:"<<strenght<<endl;
        cout<<"Dexterety:"<<dex<<endl;
        cout<<"Armor:"<<armor<<endl;
        cout<<endl;
        cout<<"Gold:"<<money<<endl;
        cout<<endl;
        system ("Pause");
    }
}

}while(quit = false);


int lvlUp(int hp, int str, int dext, int lvl){
lvl=lvl+1;
hp=hp + (0.20*hp);
str=str + (0.20*str);
dext=dext + (0.20*dext);
return lvl;
return hp;
return str;
return dext;
}
}


A informática chegou para resolver problemas que antes não existiam

Quem ri por último é porque está conectado a 52 Kbs.

Share this post


Link to post
Share on other sites
Psilvestre

Obrigado ;), não acredito que ainda nao sei estas coisas basicas :wallbash:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.