Ok so i hasve a class and i cant access a string or another variable for some reason, what am i doing wrong? im trying to use name and age in main. also in save.
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 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <string>
using namespace std;
class Vars
{
public:
void Bank();
void Save();
Vars()
{
money = 0;
level = 1;
name;
age;
}
private:
int money;
int level;
int age;
string name;
};
int main()
{
Vars VO;
VO.age;
string choice;
cout << "New" << endl;
cout << "Load\n" << endl;
cin >> choice;
if(choice == "New" || choice == "new")
{
cout << "Please enter your name\n" << endl;
cin.ignore(556, '\n');
getline(cin, name);
cout << "\n";
cout << "Ok thanks " << name << " What is your age?\n" << endl;
cin >> age;
cout << "\n";
cout << "Ok so your name is " << name << " and your " << age << " years old" << endl;
cin.get();
VO.Bank();
}
else if(choice == "Load" || choice == "load")
{
}
}
void Vars::Bank()
{
}
void Vars::Save()
{
Vars VO;
ofstream file("Bank.txt");
file << name << endl;
file << age << endl;
}
|
C:\Users\ellie\Desktop\Bank teller\main.cpp||In constructor 'Vars::Vars()':|
C:\Users\ellie\Desktop\Bank teller\main.cpp|15|warning: statement has no effect|
C:\Users\ellie\Desktop\Bank teller\main.cpp|16|warning: statement has no effect|
C:\Users\ellie\Desktop\Bank teller\main.cpp||In function 'int main()':|
C:\Users\ellie\Desktop\Bank teller\main.cpp|21|error: 'int Vars::age' is private|
C:\Users\ellie\Desktop\Bank teller\main.cpp|29|error: within this context|
C:\Users\ellie\Desktop\Bank teller\main.cpp|29|warning: statement has no effect|
C:\Users\ellie\Desktop\Bank teller\main.cpp|40|error: 'name' was not declared in this scope|
C:\Users\ellie\Desktop\Bank teller\main.cpp|44|error: 'age' was not declared in this scope|
C:\Users\ellie\Desktop\Bank teller\main.cpp||In member function 'void Vars::Save()':|
C:\Users\ellie\Desktop\Bank teller\main.cpp|69|error: variable 'std::ofstream file' has initializer but incomplete type|
||=== Build finished: 5 errors, 3 warnings ===|