Question

Write a C++ program that will calculate how much of a profit an investor will make. You will need to ask the user for the fol
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<iomanip>
using namespace std;

int main(){
   cout<<fixed<<setprecision(2);   //to set floating point max 2 value after point
   long int num_shares_purchased;   //to store number of shares purchased
   double curr_price;   //to store current price
   double purcha_price;   //to store purchase price
  
   cout<<"Enter number of shares purchased : ";
   cin>>num_shares_purchased;   //asking and entering total shares purchased from user
   cout<<"Enter purchase price of the stock : ";
   cin>>purcha_price;   //asking and entering purchase price
   cout<<"Enter current price of the stock : ";
   cin>>curr_price;   //asking and entering current price
  
   double profit = (num_shares_purchased*curr_price)-(num_shares_purchased*purcha_price);   /*calculating profit as per given formula*/
   //printing result in a formatted way
   cout<<"\n\nYou have made a profit of $ "<<profit<<" dollars since you bought "<<num_shares_purchased<<" shares of this stock.\n";   
}

//Output

C:\Users\AdiShakti NavDurga\Desktop\share.exe Enter number of shares purchased : 20 Enter purchase price of the stock : 2000

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that will calculate how much of a profit an investor will make....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • If anyone can make this coded in C++ language. Thank You Lab2 (1) Protected View -...

    If anyone can make this coded in C++ language. Thank You Lab2 (1) Protected View - Saved to this PC w Design Layout ReferencesMailings Review View Help Tell me what you want to do ue: reo.2u Q1. Write a program that will read your initials and five test scores. Your program should then compute your test average and print all information in a reasonable form with suitable messages Note: use two character variables to read input from the user (storing...

  • I need help with using the infile and outfile operations in C++... Here's my assignment requirements:...

    I need help with using the infile and outfile operations in C++... Here's my assignment requirements: Assignment: 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 read input from a file called Stock.txt: 1. The...

  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • The 4th deliverable is to create the program the makes the buy recommendation. It uses the...

    The 4th deliverable is to create the program the makes the buy recommendation. It uses the class Stock to store and retrieve the stock information. I need to make this program compatible with my stocks class. Program I need to change: #include <iostream> #include <cmath> #include <fstream> #include <iomanip> #include <string> #include <stdlib.h> using namespace std; // read the data file, store in arrays int openDatafile(ifstream&,string [], float[], float[], int[]); // opens the data file void readData(ifstream &, string[], float[],...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • I need help with my coding for C++! The goal of this is to calculate the...

    I need help with my coding for C++! The goal of this is to calculate the total cost of a product by combining the products price and the amount of tax, then display it to the user. The numbers we have to test out is 100 for the price and 8.25 for the percentage. When I test is out, the formula works but it isn't rounding the 108.25 to 108.3, which is the total price we are supposed to display...

  • This is for my c++ class and I would really appreciate the help, Thank you! Complete...

    This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT