in C++ Write a program. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none can be less than zero) and should then pass them to a function called numberfunction.The function should use the following formula to determine the profit: Profit = ((number of shares*Sale Price)-Sale commission)-((Number of shares*Purchase Price)-Purchase Commission)
also write functions for each of the values you need to take in from the user. Each function should take in a value from the user, validate it, and once the value is valid, return it back to the main. The main should then call numberfunction to compute the result
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e; // USE DOUBLE IF NEEDED AND CHANGE THE DATATYPE INSIDE
cout << "Enter the Number of shares purchased";
cin>>a;
cout << "Enter the purchase price per share";
cin>>b;
cout << "Enter the commission for the purchase";
cin>>c;
cout << "Enter the sales commision paid";
cin>>d;
cout << "Enter the price the shares where sold at: ";
cin>>e;
if(a>0 && b>0 && c>0 && d>0 && e>0)
{
int sum=NumberFunction(a,b,c,d,e);
cout << "The profit is :" << sum;
}
return 0;
}
int NumberFunction(int q,int w,int r,int t,int y)
{
return (((q*y)-t)-((q*w)-r));
}
//THIS IS MORE EFFICIENT APPROACH FOR THE PROBLEM ! TO VALIDATE INPUTS FOLLOW THE SAME //SYNTAX USED TO CALL NUMBERFUNCTION AND PUT THE IF CONDITION INSIDE IT
Get Answers For Free
Most questions answered within 1 hours.