vendredi 3 avril 2015

Need help figuring out what im doing wrong in my if Statement

Im still learning C# with Windows Forms and i would like some help with my if statement. The variables are fixed so there is going to be no user input other than them just clicking one button. Where my issue begins is at the beginning of the if statement. VS(Visual Studios) constantly says that the "half" and "calc" in the condition, and the "hours" for the conversion to string are all unassigned local variables. Then in the else statement where the math equation is, VS keeps saying that "hours" cannot be converted from double to hours. I dont know what that means because i already declared them. Then it says the "thirtheenpercent" cannot be declared in the scope because it has already been declared. I dont know why its saying this because this double is not supposed to change. Can someone help me and explain why i am getting these errors? Any help would be greatly appreciated.



double onecup = 130;
double thirtheenpercent;
double hours;
double hourlycups;
double half=130/2;
double calc=0;

thirtheenpercent=(onecup*13)/100;

if (half == calc)
{
//If the value of half equals calc, then output the hours to the label as a string//
mtbHalf.Text = hours.ToString();
}
else
{
//Else, then run this equation until calc does equal half and increase the hours by one each time the equation runs.
hours * thirtheenpercent = calc;
hours++;

}

Aucun commentaire:

Enregistrer un commentaire