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
// Program Written By Matt Prahl
// Thanks to ShackStar from CPlusPlus.com for the enumeration help.
#include <iostream>
#include <iomanip>
usingnamespace 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");
}
elseif( 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");
}
elseif( 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;
}