Description
The purpose of this challenge is to use the IF statement to control program flow and to use basic arithmetic expressions. This challenge simulates a rudimentary stock chart.
Requirements
- Take a glance at the Sample Interaction below to get an idea of how the code runs
- Declare a double variable called previous_price
- Declare a double variable called current_price
- Declare a string variable called symbol
- Declare a string variable called company
- Ask the user to enter a value for symbol
- Ask the user to enter a value for company
- Ask the user to enter a value for previous_price
- Ask the user to enter a value for current_price
- If the price of the stock has increased, show a message “It’s a bull market”
- If the price of the stock has decreased, show a message “It’s a bear market”
- if the price of the stock didn’t change, show a message “It’s a flat market”
- Also, as part of the message for steps 10 and 11, indicate the percentage change. (see below)
Formatting your output
- Include the <iomanip> header file. This will allow you to use various options to format your output. Add this line under your main include line. See below.
#include <iostream> #include <iomanip>
- It’s good practice to initialize variables to default values that make sense (for example, set fee to 0.00)
- Include the code below before any other cout lines. The setprecision(x) will display your decimal output with x decimal places.
cout << fixed << setprecision(2);
Sample Interaction / Output
-- Welcome to CSUB Brokerage -- What is the stock symbol? GOOG What is the company name? Google What was the previous stock price? 850 What is the current price? 1000 It's a bull market! Google (GOOG) went up 17.65%
RUN IT AGAIN:
-- Welcome to CSUB Brokerage -- What is the stock symbol? GOOG What is the company name? Google What was the previous stock price? 850 What is the current price? 425 It's a bear market! Google (GOOG) went down 50.00%.
RUN IT AGAIN:
-- Welcome to CSUB Brokerage -- What is the stock symbol? GOOG What is the company name? Google What was the previous stock price? 850 What is the current price? 850 It's a flat market! Google (GOOG) stock price didn't change.
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-FLOW0005
Print Requirements