If I have a private variable in a header file, then it can only be accessed directly by the corresponding .cpp file, else it needs public methods to access them, yes? Why would I get an error from a .cpp file saying that these variables are unidentified?
.h file is as follows:
and the .cpp file is:
/*5. Write a program to compute a water and sewage bill. The input is the number of gallons consumed.
The bill is computed as follows: water costs .21 dollars per gallon of water consumed sewage service .01 dollars per gallon of water consumed.*/
cout<<"Welcome to question 5"<<endl;
cout<<"Please enter the number of gallons of consumed and the number of sewage used."<<endl;
cin>> potable; //here is where it says the error is
cin>> nonPotable; //and here
nonPotable= nonPotable *.01; //and here
cout<< "The cost of water consumed is $"<< potable */and here*/<<". The cost of the sewage used is $"<< nonPotable <<"." << endl<< "The total cost of this months services is $"<<potable+nonPotable<<"."<<endl;
If I have a private variable in a header file, then it can only be accessed directly by the corresponding .cpp file, else it needs public methods to access them, yes?
No. When you #include a *.h file, the preprocessor copies that whole file exactly into place where the #include is. That's it. There is no magic link between a cpp and an h file with corresponding names.