Calculating Earnings per Share
As an assignment we have to calculate the earnings per share and earnings yield. I am using Visual C++ to create this calculator. The calculator has to be in a form with the correct buttons. I created the form but after writing the code I keep getting NaN as the answer. This is what I've written:
// Code for calculating Earnings per Share
double earnings;
double profit;
double shares;
earnings = Convert::ToDouble(tbProfit->Text);
earnings = profit;
earnings = Convert::ToDouble(tbShares->Text);
earnings = profit / shares;
tbEarnings->Text = Convert::ToString(earnings);
tbEarnings->Text = earnings.ToString(".00");
//Code for Calculating Earnings Yield
double price;
double yield;
yield = Convert::ToDouble(tbEarnings->Text);
yield = earnings;
yield = Convert::ToDouble(tbPrice->Text) / price;
yield = (earnings / price) * 100;
tbYield->Text = Convert::ToString(yield);
tbYield->Text = yield.ToString(".00");
After it compiles, the Earnings per Share and Earnings Yield text box show "NaN". Am not sure where I went wrong. I would appreciated any help given. This assignment is due in a couple hours and I don't what to do anymore.
Thank you