Question:
Cindy uses the services of a brokerage firm to buy and sell stocks. The firm
charges 1.5% service charges on the total amount for each transaction, buy
or sell. When Cindy sells stocks, she would like to know if she gained or
lost on a particular investment. Write a program that allows Cindy to input
the number of shares sold, the purchase price of each share, and the selling
price of each share. The program outputs the amount invested, the total
service charges, amount gained or lost, and the amount received after selling
the stock.
The code works correctly for some inputs, however does not display the correct output in money.
I know which output line you're having trouble with. I dont know why you are having trouble with them. You do the calculations which you've written yourself. I need to know what output you are expecting given a certain input. Otherwise I cant really help you, since it is just executing the equation that you wrote.
Hello Cindy, How much shares would you like to sell today?
1
What is the purchase price of each share?
2
What is the selling price of each share>
3
The amount you invested is: $2
The service charge is: $0.03
The amount you gained is: $-1.03
You gained: $-1.03
// Instead of outputting $-1.03, it should output $0.97, and so on for any other outputs to be correct. How do I code the program in such a way to include correct money conversion? Can you / someone offer tips?
How do I code the program in such a way to include correct money conversion?
I have no idea what you mean. Correct money conversion? You have a formula, you wrote the formula in code, and the formula is being executed perfectly and outputted. What else do you want? Either you have the wrong formula or there is something that we're missing. It's a huge waste of time when we have to beat around the bush so it would be great if you could just give us all the information we need, and tell us what you actually want. Why should it be $0.97? Using your formula and inputed values it should not be that, but rather $-1.03.
The output should be $0.97 because "Cindy" bought the share for 2 ($2.00) she plans to sell the share for 3 ($3.00) therefore 3 - 2 = 1; therefore Cindy earned 1 ($1.00), but there is a service charge fee associated with the service ($0.03) , this value is subtracted from what she earned.
So, $1.00 - $0.03 = $0.97.
My program is computing the equation wrong, can anyone help me with this or offer any tips?
#include <iostream>
int main()
{
double shares;
double sharePrice;
double sellShare;
double totalSell;
double totalShare;
double servCharge;
double absoTotal;
std::cout << "Hello Cindy, How much shares would you like to sell today? ";
std::cin >> shares;
std::cout << "What is the purchase price of each share? ";
std::cin >> sharePrice;
std::cout << "What is the selling price of each share? ";
std::cin >> sellShare;
totalSell = shares * sellShare;
totalShare = shares * sharePrice;
std::cout << "\nThe amount you invested is:\t$" << totalShare << std::endl;
std::cout << "The total sell is:\t\t$" << totalSell << "\n";
std::cout << "The service charge is:\t\t$"<< totalShare *.015 << std::endl;
servCharge = totalShare * .015;
std::cout << "The amount you gained is:\t$"<< totalSell - totalShare - servCharge << std::endl;
absoTotal = totalSell - servCharge;
std::cout << "You gained a total of:\t\t$" << absoTotal << std::endl;
}
Hello Cindy, How much shares would you like to sell today? 1
What is the purchase price of each share? 2
What is the selling price of each share? 3
The amount you invested is: $2
The total sell is: $3
The service charge is: $0.03
The amount you gained is: $0.97
You gained a total of: $2.97