Hello herhsey1234,
Back when I was in school one of the classed I took the instructor said that in the early days of programming it was
10% planning and
90% coding. This later evolved into
90% planning and
10% coding.
So the first question would be what have you planned?
I also like to rework the unstructions into something that looks like small steps:
This is a simple program to calculate stock prices based on user input.For instance, if Kathryn bought 750 shares
of stock at a price of $35.00 per share. She must pay her stockbroker a 2 percent commission for the transaction.
Below are the details.
1. Prompt the user for:
• number of shares
• price per share
• and commission rate.
2. Store these in local variables.
3. All values must be stored in well - formed, commented, local variables and use
standard mathematical operators to perform the calculations.
4. Have your program calculate and display the following:
• The amount paid for the stock alone(without the commission).
• The amount of the commission.
• The total amount paid(for the stock plus the commission).
|
If you have not planned your program then working in small steps is usually a good approach.
Start with step (1). Write a program to collect the user input. This also gives you an idea of what variables you will need.
Step (2) tends to go along with step (1). Not really an individual step to work on.
Step (3) also goes along with step (1) and most important is
All values must be stored in well - formed, commented, local variables
. Easier to write the comments as you define the variables then it is to go back later and add the comments.
Write the prompts and collect the input. Compile often and test the code to make sure it works the way that you want. Here is an idea for the first entry:
1 2
|
std::cout << "\n How many shares of stock would you like: ";
std::cin >> shares;
|
The opening "\n " is optional. This makes what is displayed on the screen easier to read. This is not required. Most who are new to programming think the the first line should end with "std::endl" although this is OK by leaving it off the "cin" will be on the same line as the prompt, which IMO looks better, also notice the space that follows the colon.
The wording of the above prompt can be changes to anything you would like. It is only a suggestion.
Finish out getting the input and post the code that you have worked up. Any problems that you have can be worked out or pointed out.
Hope that helps,
Andy