How to show output NOT in scientific notation

I am writing a tax calculation program for class and am having trouble with two parts.
One: My output is being displayed in scientific notation, and I would like it not to be.

Two: One of my values is not showing the same return as the sample solution. Any direction would be greatly appreciated.

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
  #include <iostream>
#include <string>
using namespace std;

int main()
{
	
	// variable declaration
	string stockName;
	int shares;
	float purchPrice, sellPrice, 
	sellComPer = 0.015, buyComPer = 0.02, taxRate = 0.25;
	
	// user input
	cout << "Enter the name of the stock:" << endl;
	cin >> stockName;
	cout << "Enter the number of stock shares purchased:" << endl;
	cin >> shares;
	cout << "Enter the buy price per share:" << endl;
	cin >> purchPrice;
	cout << "Enter the stock's selling price per share:" << endl;
	cin >> sellPrice;
	cout << "\n\n\n";
	
	// calculations
	float purchCom = (purchPrice * shares) * buyComPer;
	float sellCom = (sellPrice * shares) * sellComPer;
	float purchCost = (purchPrice * shares) + purchCom;
	float totalSale = (sellPrice * shares) - sellCom;
	float totalReturn = totalSale - sellCom;
	float netGain = totalReturn - purchCost;
	float tax = netGain * taxRate;
	
	// program output
	cout << "Results for " << shares << " shares of " << stockName << " stocks.\n";
	cout << "-------------------------\n";
	cout << "Buy Comission....." << purchCom << endl;
	cout << "Total Cost........" << purchCost << endl;
	cout << "Sell Commission..." << sellCom << endl;
	cout << "Total Return......" << totalReturn << endl;
	cout << "Net Profit/Loss..." << netGain << endl;
	cout << "Tax/Credit........" << tax << endl;
	return 0;
}
Hello al bama cpp,

By putting a green check on your post you are telling everyone that you have an answer and are finished. I believe that you can use the "edit" button to change the icon.

Next "double" is the preferred floating point type these days. It is more accurate than the "float".

For your output include the header file "iomanip" and put this before your output:
std::cout << std::fixed << std::showpoint << std::setprecision(2);. This only needs to be done once. "showpoint" will print ".00" if it appears. The number in "setprecision" is the number of decimal places that will print.

One of my values is not showing the same return as the sample solution.

So where is the sample data that you are looking at? Do not expect everyone to immediately know which calculation is incorrect. Those who work with calculations like this may see the problem the rest will need some idea about what is wrong, i.e., point out which calculation is not giving the right answer.

Hope that helps,

Andy
Topic archived. No new replies allowed.