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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <iomanip>
using namespace std;
void load(char *, float &, int &, float &);
void calc(float &, float &, float &, float, int, float);
void load(char *name, float &pp, int &sh, float &cp)
{
cout << "Enter the name of the stock: ";
cin.getline(name, 50);
cout << "Enter purchase price: ";
cin >> pp;
cout << "Enter number of shares: ";
cin >> sh;
cout << "Enter current price: ";
cin >> cp;
cout << endl;
}
void calc(float &ic, float &cv, float &pr, float pp, int sh, float cp) //anything being returned has to be returned with a reference "&"
{
//run calculations
ic = pp * sh;
cv = cp * sh;
pr = cv - ic;
//print out results of said calculations in proper money format
cout << "Initial Cost: " << setprecision(2) << showpoint << fixed << '$' << ic << endl;
cout << "Current Value: " << setprecision(2) << showpoint << fixed << '$' << cv << endl;
cout << "Profit: " << setprecision(2) << showpoint << fixed << '$' << pr << endl;
}
int main()
{
char name;
float pp;
int sh;
float cp;
float ic;
float cv;
float pr;
load(&name, pp, sh, cp); //notice call by pointer
calc(ic, cv, pr, pp, sh, cp);
return 0;
system("PAUSE");
}
|