i making small project, using variables , classes:
when change variables using default constructor values don't change.
water::water() { cout<<"what do?"<<endl; cout<<"0. current stats of water"<<endl; cout<<"1. raise water temperature degrees"<<endl; cout<<"2. decrease water temperature degrees"<<endl; cin >> do_what; cout<<do_what; switch(do_what) { case 0 :check_status(); break; case 1 :heat_water(); break; default:cout<<"enter proper value!"<<endl; //system("cls"); //water(); break; } }
this default constructor. not able change variable values declared in main class class water
in main
function create water
object named w1
working with. when calling functions (e.g. add_ph
, add_temp
) on object , call water()
again, not reconstruct w1
object: creating new water
object, constructing , gets destructed straight away. can see putting break point in water::water
, water::~water
(the constructor , destructor, respectively).
if trying modify original water
object, w1
, should create reset
function resets things want (which assume print console stuff , ask user input again?).
you may want try following:
int main() { // create water object work water w1; char input = 'q'; { // ask user input input = askforinput(); processinput(input, w1); // process input until user wishes quit } while (input != 'q') return 0; }
note answer based on code linked , original question.