how to use If else stament
Sep 17, 2012 at 3:21am UTC
I have to create a earnings yield calculator and here is what I have so far. But i want to be able to calculate when Profit and Shares Outstanding are missing. When I don't any input in Profit and Shares Outstanding I get an error message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//declare variables
double EPS;
double EY;
//if stament to make sure users enters all necessary variables
if ((this ->tbProfit->Text == String::Empty ) &&
(this ->tbSharesOutstanding->Text == String::Empty )&&
(this ->tbSharePrice->Text == String::Empty) ){
MessageBox::Show("Please insert Profit, Shares Outstanding and Shares Price" );
}
if ((Convert::ToDouble(tbProfit->Text)&& Convert::ToDouble(tbSharesOutstanding->Text) != 0)&&
(Convert::ToDouble(tbSharePrice->Text)&& Convert::ToDouble(tbEPS->Text)!= 0))
{
EPS = Convert::ToDouble(tbProfit->Text)/Convert::ToDouble(tbSharesOutstanding->Text); //Calculates EPS
tbEPS->Text = EPS.ToString(".00" );
EY = Convert::ToDouble(tbEPS->Text)/ Convert::ToDouble(tbSharePrice->Text)*(100); //calculates EY
tbEarningsYield->Text = EY.ToString(".00" );
}
// else stament to calculate EY if Profit and Shares Outstanding are not giving
else
{(Convert::ToDouble(tbProfit->Text)&& Convert::ToDouble(tbSharesOutstanding->Text)!= 0);
EY = Convert::ToDouble(tbEPS->Text)/ Convert::ToDouble(tbSharePrice->Text)*(100);
tbEarningsYield->Text = EY.ToString(".00" );
}
}//ends bnCalculate
Last edited on Sep 18, 2012 at 4:43am UTC
Topic archived. No new replies allowed.