Question

When you buy and sell stock you have to account for your profit or loss on...

When you buy and sell stock you have to account for your profit or loss on your income taxes and what taxes you pay depends on how long you held the stock. So, knowing when you purchased a stock and how much you paid is a question your tax preparer will ask. (Make sure you keep a record of this.) Most of you will be in this position within a few years so this is a little introduction.

Write a script that will respond for a purchase according to the following:

  • Enter the purchase date of the stock
  • Enter the purchase price of the stock
  • Enter the sale date
  • Enter the sale price
  • If the sale is a loss (sale price – purchase price is negative)
    • assign a variable Tax_Credit for this amount.
    • If the sale is a winner, Tax_Credit = 0.
  • Use the function datenum( ) to determine the period that you owned the stock. You used this in a previous exercise.
    • Assign a variable for Tax owed
    • If the Tax_Credit > 0 then Tax = 0
    • If the period that you owned the stock is greater than 3 years then
      • Tax = 0.15 * (sale price – purchase price)
      • This is “long term capital gains tax”
    • If the period is less than 3 years then
      • Tax = 0.25 * (sale price – purchase price)
      • This is “short term capital gains tax” taxed as ordinary income
    • Use fprintf() statements to tell which scenario applied and repeat the appropriate information in the fprintf( ).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

struct Date
{
int d, m, y;
};
  
const int monthDays[12] = {31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31};

int countLeapYears(Date d)
{
int years = d.y;

if (d.m <= 2)
{
years--;
}
return years / 4 - years / 100 + years / 400;
}

int getDifference(Date dt1, Date dt2)
{
long int n1 = dt1.y*365 + dt1.d;

for (int i=0; i<dt1.m - 1; i++)
{
       n1 += monthDays[i];
}

n1 += countLeapYears(dt1);

long int n2 = dt2.y*365 + dt2.d;
for (int i=0; i<dt2.m - 1; i++)
{
   n2 += monthDays[i];
}
n2 += countLeapYears(dt2);

return (n2 - n1);
}

int main()
{
   Date dt1, dt2;
   double purchasePrice, salePrice, Tax_Credit, priceDiff, tax;
   cout << "Enter the purchase date of the stock [d m yyyy]: ";
   cin >> dt1.d >> dt1.m >> dt1.y;

   cout << "Enter the purchase price of the stock: ";
   cin >> purchasePrice;

   cout << "Enter the sale date [d m yyyy]: ";
   cin >> dt2.d >> dt2.m >> dt2.y;

   cout << "Enter the sale price: ";
   cin >> salePrice;

   if((priceDiff = salePrice - purchasePrice) < 0)
   {
       Tax_Credit = priceDiff;
   }
   else
   {
       Tax_Credit = 0.0f;
   }
  
   if(Tax_Credit > 0)
   {
       tax = 0;
   }

   char str[100] = {'\0'};
   double dateDiff = static_cast<double>(getDifference(dt1, dt2)/365);
   if(dateDiff > 3.0) //Greater than 3 years
   {
       tax = 0.15 * priceDiff;
       strcpy(str, "long term capital gains tax");
   }
   else
   {
       tax = 0.25 * priceDiff;
       strcpy(str, "short term capital gains tax");
   }

   FILE *fptr = fopen("TaxCalculator.txt", "w");
   if(nullptr == fptr)
   {
       cout << "Unable to open file." << endl;
   }
   else
   {
       fprintf(fptr, "%s is: $%f\n", str, tax);
   }
   fclose(fptr);
  
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
When you buy and sell stock you have to account for your profit or loss on...
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
  • ​​​​​​Why is the gain on the sale of a houseboat which is used for personal purposed...

    ​​​​​​Why is the gain on the sale of a houseboat which is used for personal purposed taxes at a capital gains rate and not an ordinary rate? Discussion Question 3-18 (LO. 8) During the year, Hernando has the following transactions: a. Gain on the sale of stock held as an investment for 10 months. b. Gain on the sale of land held as an investment for 4 years. C. Gain on the sale of a houseboat owned for 2 years...

  • pick 1 of the five things you should know about capital gains tax, and give a...

    pick 1 of the five things you should know about capital gains tax, and give a pro or con point of view on the artical. Paragraph Styles 6 5 Things You Should Know about Capital Gains Tax Updated for Tax Year 2019 OVERVIEW A capital gain occurs when you sell something for more than you spent to acquire it. This happens a lot with investments, but it also applies to personal property, such as a car. Every taxpayer should understand...

  • "New Tax Codes and Stock" Calvin, a client of yours since you opened your practice, has...

    "New Tax Codes and Stock" Calvin, a client of yours since you opened your practice, has over the past few years become very intrigued with investing in the stock market. He has interest bearing securities and dividend paying stocks. He also owns U.S. Securities. He is considering selling $400,000 in stocks. He doesn’t know if he should sell additional stock for a loss to help offset the stock sale of $400,000. Calvin called you to ask what tax consequences the...

  • You purchased a stock at the end of the prior year at a price of $83. At the end of this year, the stock pays a dividen...

    You purchased a stock at the end of the prior year at a price of $83. At the end of this year, the stock pays a dividend of $2.00 and you sell the stock for $95. What is your return for the year? Now suppose that dividends are taxed at 15 percent and long-term capital gains (over 11 months) are taxed at 30 percent. What is your after-tax return for the year? (Do not round intermediate calculations. Enter your answers...

  • Wkd #8 Can you please read the question and answer posted below and re-write it for...

    Wkd #8 Can you please read the question and answer posted below and re-write it for me. I don't understand it to re-write it. Please and thank you. Stock Options Five years ago Roger was granted 5,000 incentive stock options and 3,500 nonqualified stock options. At that time the stock price was $20 per share. The ISO exercise price was $20 per share and the NSO exercise price was $2 per share. The value of the nonqualified options at the...

  • 7. There is a trading rule that goes: Buy the rumor, sell the news! Which of...

    7. There is a trading rule that goes: Buy the rumor, sell the news! Which of the following actions most likely violates this rule: The investor purchased shares on January 1st, 2018 The investor purchased shares on December 1st, 2018 The investor sold shares on December 2nd, 2018 This investor sold shares on January 1st, 2019 I II III I,IV I,II,III,IV Use the following information from questions 6-12. In both 2018 and 2019 you expect to receive a W2 for...

  • Jason and Jill are married and have a six-year-old daughter. During the year, they sell one...

    Jason and Jill are married and have a six-year-old daughter. During the year, they sell one acre of land for $80,000. Three years ago, they paid $70,000 for two acres of land. Their other income and deductions are as follows: Jill's commissions $82,000 Jason's salary 46,000 Dividend income 5,000 Interest income 8,000 Short-term loss on sale of stock in Nippon Inc. (15,000) 28,000 Deductions for adjusted gross income The standard deduction is $24,000 for married taxpayers filing jointly. The personal...

  • 9. For this question only, assume you sold all of your stock on July 1st, 2018....

    9. For this question only, assume you sold all of your stock on July 1st, 2018. What was your total return on the investment? (8%) (4%) (2%) 0% 4% Use the following information from questions 6-12. In both 2018 and 2019 you expect to receive a W2 for $200,000; $65,000 will be already withheld on your W2 for federal income taxes and your income tax bracket is 32%. The short term capital gains on investments (<1 year) are taxed like...

  • 5. Margin Calls (LO3, CFA4) You buy 500 shares of stock at a price of $38...

    5. Margin Calls (LO3, CFA4) You buy 500 shares of stock at a price of $38 and an initial margin of 60 percent. If the maintenance margin is 30 percent, at what price will you receive a margin call? 6. Margin Calls on Short Sales (L04, CFA5) You short sold 1,000 shares of stock at a price of S36 and an initial margin of 55 percent. If the maintenance margin is 35 percent, at what share price will you receive...

  • Mark received 10 ISOs (each option gives him the right to purchase 14 shares of Hendricks Corporation stock for $7 per s...

    Mark received 10 ISOs (each option gives him the right to purchase 14 shares of Hendricks Corporation stock for $7 per share) at the time he started working for Hendricks Corporation five years ago when Hendricks’s stock price was $5 per share. Now that Hendricks’s share price is $35 per share, Mark intends to exercise all of his options and hold all of his shares for more than one year. Assume that more than a year after exercise, Mark sells...

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