Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm just a beginner.
But why is this showing error ? I think I have used the syntax as per the one given in MSDN site.


double power;
double baseNumber;
double FINALnumber ;

FINALnumber  = Math.Pow(baseNumber, power);
Posted
Updated 20-Jun-13 2:31am
v5
Comments
Rajesh Anuhya 20-Jun-13 8:08am    
What is the Error message?
--RA
Allwin456 20-Jun-13 10:54am    
this is the error message - Use of unassigned local variable 'power' .. I can rectify it by initializing the values but is there any way to initialize value during run time ?

for eg, I can rectify the error as answered by others like this -

double power = 10;
double baseNumber = 5;

double FinalNumber = Math.Pow(power, baseNumber);


But can I assign the value to 'power' and 'baseNumber' during runtime ?
Allwin456 20-Jun-13 11:08am    
yeah I found it -

double baseNumber = 10;
int power = int.Parse(Console.ReadLine());
double limit ;

limit = Math.Pow(basenumber, power);

You are trying to use the uninitialised variable power. Try something similar to:
C#
double power = 3;
double limit = Math.Pow(10, power);
 
Share this answer
 
Comments
Ron Beyer 20-Jun-13 8:16am    
Got me by mere miliseconds +5 :)
CPallini 20-Jun-13 10:46am    
Thanks.
Rajesh Anuhya 20-Jun-13 9:04am    
Have my +5
CPallini 20-Jun-13 10:46am    
Thanks.
Allwin456 20-Jun-13 10:55am    
But can I assign the value to 'power' and 'baseNumber' during runtime ? Is there any way ?
Because you haven't assigned anything to power or base number.

C#
double power = 10;
double baseNumber = 5;

double FinalNumber = Math.Pow(power, baseNumber);
 
Share this answer
 
v2
Comments
Rajesh Anuhya 20-Jun-13 9:04am    
Have my +5
CPallini 20-Jun-13 10:47am    
My 5 too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900