(*I know this question has been answered before on Stack Overflow, but none of those answers worked for me)
I am creating a sort of banking game (text only) using basic c++. I am getting an error on one of my if statements when trying to create a function that allows the user to deposit money in one of the 4 vaults. The error is:
main.cpp: In member function 'int bank::moneyChange::deposit_money()':
main.cpp:58:10: error: 'vaultNum' was not declared in this scope
if(vaultNum == 1) {
I am trying to figure out how I can get the scope to extend to the moneyChange class.
My C++:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
class bank {
class bankName{
public:
string bank_name(string) {
string bank_name;
cout << "Choose your bank name! : ";
cin >> bank_name;
return bank_name;
}
};
class vaults{
public:
int findVault(){
int vaultNum;
cout << "Which vault do you want to open? (1, 2, 3, or 4 ?)" << endl;
cin >> vaultNum;
if(vaultNum == 1) {
vaultNum = 1;
return vaultNum;
}
else if(vaultNum == 2) {
vaultNum == 2;
return vaultNum;
}
else if(vaultNum == 3) {
vaultNum == 3;
return 0;
}
else if(vaultNum == 4){
vaultNum == 4;
return 0;
}
else{
cout << "Did you choose a valid number? (1, 2, 3, or 4) " << endl;
findVault();
}
}
};
class moneyChange{
public:
int vaultnumber1Money = 250000;
int depositAmount;
if(vaultNum == 1) {
cout << "Vault Number 1 has 250000 dollars in the bank" << endl;
cout << "How much money do you want to deposit?" << endl;
cin >> depositAmount;
int vaultnumber1Money = vaultnumber1Money + depositAmount;
return vaultnumber1Money;
}
}
};
};
int main()
{
}
};
Aucun commentaire:
Enregistrer un commentaire