I've got a question. In C++, if I decide I do not need a variable anymore, how do I remove it?
EG:
int personAge;
std::cout << "Enter your age: ";
std::cin >> personAge;
std::cout << "Your name is " << personAge;
ok, not the best example, but in this, I have no further need of personAge. I suppose I could resuse it:
EG:
int personAge;
std::cout << "\nEnter your age: ";
std::cin >> personAge;
std::cout << "\nYour name is " << personAge;
std::cout << "\nEnter your phone number: ";
std::cin >> personAge; // personAge == phoneNumber?!?!
std::cout << "\nYour phone number is " << personAge;
See? doesn't seem practical. I could wait for it to go out of scope...
EG:
int happyFunc()
{
int cool;
cool = 38;
std::cout << "\nThe number " << cool << " is really cool!";
std::cout << "\nAlso, I don't need \"cool\" anymore!";
}
OK for short functions, but what if it's main(), or if the function is really big?? back to my first example:
int happy;
std::cout << "On a scale of 1 - 10, how happy are you?\nHappiness factor: ";
std::cin >> happy;
std::cout << "\nYour happiness factor is " << happy << "\10";
//'happy' is now redundant.
std::cout << "\n\nblah blah blah...";
How to destroy 'happy'?