Question

in C++ Write a program. The program should prompt the user for the number of shares...

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

Homework Answers

Answer #1

#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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Write most basic C++ program possible that calculates monthly savings account balance. Program will prompt user...
Write most basic C++ program possible that calculates monthly savings account balance. Program will prompt user to enter initial account balance, annual percentage rate, amount deposited each month, and total number of months. Validate user inputs allowing only positive numbers. B = initial account balance A = amount deposited each month R = annual percentage rate Total Balance = (R/12+1)B+A
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Write a C++ program to prompt a user for a positive integer and print the number...
Write a C++ program to prompt a user for a positive integer and print the number of even and odd digits (0 is even). Sample run: Enter a positive integer: -4580 Invalid. Enter a positive integer: 12146 2 odd digits 3 even digits
IN C++ PLEASE. Write a program where the user enters a number and you output an...
IN C++ PLEASE. Write a program where the user enters a number and you output an unfilled square of stars. (DO NOT PROMPT THE USER, just take in a number, The only console output should be the squares). For example the program would start with console input, The user would enters 3, you would output (note 3 is the lowest number your program will be tested with) *** * * *** or, The user enters 5, you would output *****...
step by step in python please The program will prompt the user as to whether you...
step by step in python please The program will prompt the user as to whether you want to convert from Celsius to Fahrenheit or from Fahrenheit to Celsius Write it so each conversion is contained within its own function (i.e., one function to do the math in one direction, a second to do the math in the other direction) These two functions should just have the input temperature as a parameter and return the output temperature in the other units....
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number...
Write a C++ program with a user-defined function myFactorial, that calculates the factorial of a number entered by the user. Return the calculated factorial and print it in the main function.
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...