The price of stocks is sometimes given to the nearest eighth of a dollar; for example, 29 7/8 or 89 1/2. Write a program that computes the value of the user’s holding of one stock. The program asks for the number of shares of stock owned, the whole dollar portion of the price and the fraction portion. The fraction portion is to be input as two int values, one for the numerator and one for the denominator. The program then outputs the value of the user’s holdings. Your program should allow the user to repeat this calculation as often as the user wishes. Your program will include a function definition that has three int arguments consisting of the whole dollar portion of the price and the two integers that make up the fraction part. The function returns the price of one share of stock as a single number of type double.
Program Code:
#include<iostream>
using namespace std;
double stockCost(int x, int y, int z, int stock);
void main()
{
int x, y, z, stock;
double stockVal=0;
char choice;
do
{
cout<<"\n Enter whole part of stock:";
cin >>x;
cout<<"\n Enter Numerator:";
cin>>y;
cout<<"\n Enter Denominator:";
cin>>z;
cout<<"\n Enter number of stocks:";
cin>>stock;
stockVal = stockCost(x,y,z,stock);
cout<<"\n Cost of single stock: "<>choice;
} while(choice == 'y'||choice == 'Y');
}
double stockCost(int x, int y, int z, int stock)
{
double price;
price=static_cast(x * z + y)/(z * stock);
return price;
}
Output:
Enter whole part of stock:100
Enter Numerator:10
Enter Denominator:5
Enter number of stocks:11
Cost of single stock: 9.27273
Tochoice then enter 'y' or 'Y' : n