How can I force program to end when a specific function is called for the second time ??
//EDİT: okay I understood that I can't do that.. Help me with this please.
I need to end the program when the variable vegetable is eggplant but if it's tomato the program needs to call a function. I tried something but I guess it was nonsense. It keeps calling the Which() function without caring the variable.
1 2 3 4 5 6 7
cout << name << ", you should pay " << pay << " TL to buy " << weight << " kg of " << vegetable << " and you will be left with " << change << " TL."<<endl;
cout << endl;
if (vegetable == "tomato")
Which(name, change, "eggplant");
Whoops. Yes, you are right.
Looks like only way to safely do this is to throw an exception: if it won't be cautch, it will terminate program, but it will unwound stack and will normally destroy all objects.