please help with this?

closed account (jLA4LyTq)
This program will calculate the gain or loss for stock that you have purchased and later sold.

Write a program that reads in the name of a company. Since the company name can contain spaces in the name you need to use getline to read the data into a string.

Next you will read in the number of shares of stock, a stock purchase price, and a stock sale price. The number of shares will always be an integer value.

With this data calculate the total amount required to purchase the stock. You also need to calculate the commission that has to be paid to the stockbroker. The stockbroker commission will be 2.5% of the amount required to purchase the stock.

**Note: the commission percentage should be put into a const double variable that you will use in your calculations.

Output the name of the company, the cost of a share of stock, the total amount required to pay for the stock (not including the commission), the commission, and the total cost of the stock (including the commission).

Next calculate the amount of income you will get when you sell the stock for the stock sales price. You also need to calculate the cost of the commission to the stockbroker for the sale of the stock. Again this will be 2.5% of the money you get for selling the stock.

Output the price of one share of stock, the amount of money you get from the sale (before the commission is paid), the amount of the commission, and the amount of money you get from the sale after you have paid the commission to the stockbroker. All of the money amounts should be output in a fixed format with two digits to the right of the decimal point.

Final calculate the difference between what you paid for the stock (including the commission), and what you received when you sold the stock (less the commission). This number will be negative if you have lost money.


I haven't bought the book and this is due tonight so i have no clue how to do this. Any help would be greatly appreciated please!
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However, we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

You have some study material, don't you?
I haven't bought the book and this is due tonight

Do you simply hate doing C++ exercises or are you underestimating your chances to finish them by your own? Don’t let them depress you: believe in yourself.
If you haven’t started yet, perhaps this can be a starting point:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>

int main()
{
    // Write a program that reads in the name of a company. Since the company 
    // name can contain spaces in the name you need to use getline to read the 
    // data into a string.
    std::cout << "Please enter company name: ";
    std::string compname;
    std::getline(std::cin, compname);
    
    // Next you will read in the number of shares of stock... The number of 
    // shares will always be an integer value:
    int numshares = 0;
    std::cout << "Please enter number of stock shares: ";
    // input the value inside numshares

    // a stock purchase price:
    double pur_price = 0.0;
    // ask the user for the price
    // input the value inside pur_price
    
    // and a stock sale price:
    /* type ? */ sale_price = /* initial value? */
    // ask the user for the stock sale price
    // input the value inside sale_price
    
    // With this data calculate the total amount required to purchase the stock.
    /* type? */ amount = // multiply the number of shares for their purchase price
    
    // You also need to calculate the commission that has to be paid to the
    // stockbroker. The stockbroker commission will be 2.5% of the amount 
    // required to purchase the stock.
    // **Note: the commission percentage should be put into a const double 
    // variable that you will use in your calculations.
    /* type? read the note, it says everything!! */ commission = // amount * 0.025

    // Output the name of the company:
    /* output instruction? */ << "Company name: " << compname << '\n';
    //        the cost of a share of stock:
    /* output instruction? */ << "Cost of a share of stock: " << pur_price << '\n';
    //        total amount required to pay for the stock (not including the commission):
    /* output instruction? */ << "Total amount (without commission): " << /* the proper variable */ << '\n';
    //        the total cost of the stock (including the commission):
    /* output instruction? */ << "Total without the commission: " << /* it's just a sum */ << '\n';
    
    // Next calculate the amount of income you will get when you sell the stock 
    // for the stock sales price.
    /* type? */ income = // multiply the number of shares for their sale price

    // You also need to calculate the cost of the commission to the stockbroker 
    // for the sale of the stock. Again this will be 2.5% of the money you get 
    // for selling the stock.
    // -- you don't need any help from now on: the rest is very similar to what
    //    you've done up to here.

    return 0;
}

Topic archived. No new replies allowed.