So when i input this:
Acme Software, Inc.
i'm supposed to get:
Company: Acme Software, Inc.
Cost of stock: $45500.00
Cost of commission: $1137.50
Total cost: $46637.50
Income from stock: $56900.00
Cost of commission: $1422.50
Total income: $55477.50
Gain or loss: $8840.00
But instead i get this:
Company:Acme Software, Inc.
Cost of stock:$45500.00
Cost of commission:$1137.50
Income from stock:$56900.00
Cost of commission:$1422.50
Gain or loss:$8840.00
this is my code:
using namespace std;
* string variable named companyName is declared.
* It stores name of the company.
* Using getline() function we scan companyName.
* Now an integer variable named numOfShares is declared and scanned.
* It stores total shares to buy/sale.
* Now we declare two double variables named
* purchaseShareCost and saleShareCost to store purchase price
* of each share and sale price of each share.
* Below we scan both values.(First we scan purchase cost)
* Total cost of purchase of numOfShares is calculated
* and stored in variable named totalPurchaseCost.
* Commission of 2.5% is applied to both for purchase and selling.
* 2.5% can be simplified by dividing 2.5 by 100
* So 2.5/100 becomes 0.025
const double commission= 0.025;
* Now we calculate total amount paid and store in variable named
double amountPaid=totalPurchaseCost+ commissionCost;
* We have done with purchase of shares. Now it's time
* to sell the shares and earn profit or suffer loss.
* We shares number and cost of selling each share.
* So let's calculate totalSellCost.
* Note that while calculating amount we receive we need to subtract
* commission cost as we pay commission.
double amountGain = totalSellCost - commissionOnSell;
* Now we print all the data as required in same format.
printf("\nCost of stock:$%.2f", totalPurchaseCost);
printf("\nCost of commission:$%.2f", commissionCost);
printf("\nTotal cost:$%.2f", amountPaid);
printf("\nIncome from stock:$%.2f", totalSellCost);
printf("\nCost of commission:$%.2f", commissionOnSell);
printf("\nTotal income:$%.2f", amountGain);
* Now it's time to know if we got loss or profit.
double proLoss= amountGain-amountPaid;
printf( "\n\nGain or loss:$%.2f", proLoss);