niel said:
what if i enter a value for the variable "pricePerLicense". used you codes and when i enter a value for the "pricePerLicense" the output is still in the global value.
---------- Post added at 04:17 PM ---------- Previous post was at 04:16 PM ----------
what if i enter a value for the variable "pricePerLicense". used you codes and when i enter a value for the "pricePerLicense" the output is still in the global value.
By global value do you mean the value you set to begin with?
What you do is
string inputString ;
while(true)
{
inputString = Console.ReadLine();
bool result = int.TryParse(inputString, out pricePerLicense);
if(result == true)
break;
}
I have not tested it but I think it will work. What happens is:
Console tries to read line. When line is read it tries to parse it into an int. If the parser sais OK result = true then it breaks and you can continue. If not then it tries ago. Note that this is NOT the most efficient way to write this, it could be significantly shorter, but for explaining how it all works I found this to be the best to use. Also, use "[CODE]" tags