#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string>
usingnamespace std;
struct stock {
string stock_name;
double earnings_per_share;
double est_price_to_earnings_ratio;
};
void share_price(stock);
void display_share_information(stock);
void enter_stock_info(stock);
void share_price(stock A)
{
cout << "The share price is" << A.earnings_per_share << " x " << A.est_price_to_earnings_ratio <<
" = " << A.earnings_per_share * A.est_price_to_earnings_ratio << endl;
}
void display_share_information(stock A)
{
cout << "Your values or this stock are the following" << endl;
cout << "Stock Name " << A.stock_name << endl;
cout << "Earnings per share " << A.earnings_per_share << endl;
cout << "Estimated price to earnings ratio" << A.est_price_to_earnings_ratio << endl;
}
void enter_stock_info(stock A)
{
cout << "What is the name of the stock?" << endl;
getline(cin, A.stock_name);
cout << "What is the earnings per share?" << endl;
cin >> A.earnings_per_share;
cout << "What is the estimated price to earnings ratio?" << endl;
cin >> A.est_price_to_earnings_ratio;
}
int main()
{
stock stock_1;
enter_stock_info(stock_1);
share_price(stock_1);
display_share_information(stock_1);
system("pause");
return 0;
}
[\output] What is the name of the stock?
10
What is the earnings per share?
10
What is the estimated price to earnings ratio?
10
The share price is-9.25596e+61 x -9.25596e+61 = 8.56729e+123
Your values or this stock are the following
Stock Name
Earnings per share -9.25596e+61
Estimated price to earnings ratio-9.25596e+61
[/output]
By default, in C++, function parameters are passed by value. If you want that function to return something through one of its arguments then that needs to be a reference parameter. Line 32 should be (noting the &): void enter_stock_info(stock &A)
You will also have to change the declaration on line 16 to reflect this.