Help Appreciated On My Gold and Silver Profits Program

Hello everyone,
I have written a program in C++ that allows me to calculate my gold and silver profits. I was wondering how I would go about if I wanted to do two calculations and then add them together. For instance, I want the program to ask me, how many gold coins do you own, then I would type 5, then it would ask repeat the process 5 times and add all those values together. Do you have any advice or tutorial suggestions that I may view

Thanks a lot and have a great day.

Here is my code:
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Program Written By Matt Prahl
// Thanks to ShackStar from CPlusPlus.com for the enumeration help.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	cout << fixed;
	cout << setprecision (2);

		float SilverOunce; // How many ounces of Silver
		float SilverPrice; // Current Silver price
		float GoldOunce;   // How many ounces of Gold
		float GoldPrice;   // Current Gold price
		float GoldTotal;   // Total posesssion of Gold
		float SilverTotal; // Total posession of Silver
		float GoldProfit;  // Gold Profit
		float SilverProfit; // Silver Profit
		float GoldHist;      // Gold Price when you bought it
		float SilverHist;    // Silver Price when you bought it
		float GoldSilverT;   // Gold and Silver Total
		float GoldSilverP;   // Gold and Silver Profit
		enum repeat {Yes = 1, No = 2};
		enum options {Gold = 1, Silver = 2, Both = 3};
int repeat = 0;
int option = 0;

do {

cout << "What option would you like to choose?" << endl;
cout << "(" << Gold << "): Calculate Gold" << endl;
cout << "(" << Silver << "): Calculate Silver" << endl;
cout << "(" << Both << "): Calculate Both" << endl;
cout << "\nEnter your choice: ";
cin >> option;
cout << endl;

if( option == Gold )
{
    cout << "What was the spot price of gold when you bought it?" << endl;
	cin >> GoldHist;
	cout << "\nWhat is the current spot price of gold?" << endl;
	cin >> GoldPrice;
	cout << "\nHow many troy ounces of gold do you own?" << endl;
	cin >> GoldOunce;
	cout << "\n---------------------------------------------------------\n";
	GoldTotal = GoldPrice * GoldOunce;
	cout << "\nYou currently own $" << GoldTotal << " of gold." << endl;
	GoldProfit = (GoldPrice - GoldHist) * GoldOunce;
	cout << "\nYour total profit on your investment in gold is $" << GoldProfit << ".\n" << endl;
	system ("pause");
}
else if( option == Silver )
{
	cout << "\nWhat was the spot price of silver when you bought it?" << endl;
	cin >> SilverHist;
	cout << "\nWhat is the current spot price of silver?" << endl;
	cin >> SilverPrice;
	cout << "\nHow many troy ounces of silver do you own?" << endl;
	cin >> SilverOunce;
	cout << "\n---------------------------------------------------------\n";
	SilverTotal = SilverPrice * SilverOunce;
	cout << "\nYou currently own $" << SilverTotal << " of silver." << endl;
	SilverProfit = (SilverPrice - SilverHist) * SilverOunce;
	cout << "\nYour total profit on your investment in silver is $" << SilverProfit << ".\n" << endl;
	system ("pause");
}
else if( option == Both )
{
	cout << "What was the spot price of gold when you bought it?" << endl;
	cin >> GoldHist;
	cout << "\nWhat is the current spot price of gold?" << endl;
	cin >> GoldPrice;
	cout << "\nHow many troy ounces of gold do you own?" << endl;
	cin >> GoldOunce;
	cout << "\nWhat was the spot price of silver when you bought it?" << endl;
	cin >> SilverHist;
	cout << "\nWhat is the current spot price of silver?" << endl;
	cin >> SilverPrice;
	cout << "\nHow many troy ounces of silver do you own?" << endl;
	cin >> SilverOunce;
	cout << "\n---------------------------------------------------------\n";
	GoldTotal = GoldPrice * GoldOunce;
	cout << "\nYou currently own $" << GoldTotal << " of gold." << endl;
	GoldProfit = (GoldPrice - GoldHist) * GoldOunce;
	cout << "\nYour total profit on your investment in gold is $" << GoldProfit << ".\n" << endl;
	SilverTotal = SilverPrice * SilverOunce;
	cout << "\nYou currently own $" << SilverTotal << " of silver." << endl;
	SilverProfit = (SilverPrice - SilverHist) * SilverOunce;
	cout << "\nYour total profit on your investment in silver is $" << SilverProfit << "." << endl;
	GoldSilverT = GoldTotal + SilverTotal;
	cout << "\nYou currently own $" << GoldSilverT << " in precious metals." << endl;
	GoldSilverP = GoldProfit + SilverProfit;
	cout << "\nYour total profit in your investment in precious metals is $" << GoldSilverP << ".\n" << endl;
	system ("pause");
}
	cout << endl << endl;
	cout << "---------------------------------------------------------\n" << endl << endl;
	cout << "\nWould you like to calculate anymore of your precious metals?" << endl;
	cout << "(" << Yes << "): Yes" << endl;
	cout << "(" << No << "): No" << endl << endl;
	cout << "Enter your choice: ";
	cin >> repeat;
	cout << "\n\n\n---------------------------------------------------------\n" << endl << endl;
} while (repeat == 1);


	return 0;
}
Last edited on
Topic archived. No new replies allowed.