Hello, Everyone
I am new to the programming world. I am currently taking Introduction to C++. I would appreciate any help. I am not sure if I met all the requirements for the assignment. Each time I debug I am promoted to input the 10 items, but when I attempt to test if total equity,purchase price, and annual interest rate are equal to zero it doesn't initiate correctly.
Description:
Write a C++ program to calculate 5 financial formulas*. The customer will enter 10 financial numbers and then select one of the formulas. Display the answer to each formula selected.
Requirements
1. Input the following items (10): income, expenses, total debt, total equity, investment return, inflation rate, market price, purchase price, annual interest rate.
2. Display a menu with the financial formula options. Include an exit option.
3. Create 6 functions
a. Menu
b. Cash flow
c. Leverage ratio
d. Real return
e. Percentage increase
f. Years to double investment
4. Send the appropriate data to the selected function.
5. Do not let the customer enter 0 for total equity, purchase price, and annual interest rate.
6. Design the program so the user can continuously enter a menu item and terminate the program when done.
7. Do not use global variables. All variables used in the functions must be passed as parameters or declared locally
8. Display the results
Formulas
Cash Flow = income – expenses
Leverage ratio = total debt / total equity
Real return = ((1+ investment return)/(1 + inflation rate)-1)*100
Percentage increase = (market price - purchase price)/purchase price
Years to double investment = 72/(the annual interest rate of the investment)/100
//Rahima Hamadi
//12.2.2018
//Description:Write a C++ program to calculate 5 financial formulas*.
//The customer will enter 10 financial numbers and then select one of the formulas. Display the answer to each formula selected.
double CashFlow, LeverageRatio, RealReturn, PercentageIncrease, YearsToDoubleInvestment;
//constants for menu choice
const int CASH_FLOW = 1,
LEVERAGE_RATIO = 2,
REAL_RETURN = 3,
PERCENTAGE_INCREASE = 4,
YEARS_TO_DOUBLE_INVESTMENT = 5,
EXIT = 6;
//Promoting user for input
ofstream outputFile; //Created file
outputFile.open("Financial_Information.txt");
do
{
cout << "Please enter the following Financial information:" << endl << "income:";
outputFile << income << expenses << totaldebt << totalequity << investmentreturn << inflationrate << marketprice << purchaseprice << annualinterestrate; //writing into the file
} while (totalequity = 0);
cout << "Please enter value greater than 0.";
cin >> totalequity;
while (purchaseprice = 0);
cout << "Please enter value greater than 0.";
cin >> purchaseprice;
while (annualinterestrate = 0);
cout << "Please enter value greater than 0.";
cin >> annualinterestrate;
outputFile.close(); //Closed file
ifstream inputFile;
inputFile.open("Financial_Information.txt");
outputFile.open("Menu.txt"); //opening a second file to store financial calculations
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
//defining variables
char Menu;
double income, expenses, totaldebt, totalequity, investmentreturn, inflationrate, marketprice, purchaseprice, annualinterestrate;
double CashFlow, LeverageRatio, RealReturn, PercentageIncrease, YearsToDoubleInvestment;
//constants for menu choice
constint CASH_FLOW = 1,
LEVERAGE_RATIO = 2,
REAL_RETURN = 3,
PERCENTAGE_INCREASE = 4,
YEARS_TO_DOUBLE_INVESTMENT = 5,
EXIT = 6;
//Promoting user for input
ofstream outputFile; //Created file
outputFile.open("Financial_Information.txt");
do
{
cout << "Please enter the following Financial information:" << endl << "income:";
cin >> income;
cout << "Expenses:";
cin >> expenses;
cout << "Total Debt:";
cin >> totaldebt;
cout << "Total Equity:";
cin >> totalequity;
cout << "Investment Return:";
cin >> investmentreturn;
cout << "Inflation Rate:";
cin >> inflationrate;
cout << "Market Price:";
cin >> marketprice;
cout << "Purchase Price:";
cin >> purchaseprice;
cout << "Annual Interest Rate:";
cin >> annualinterestrate;
outputFile << income << expenses << totaldebt << totalequity << investmentreturn << inflationrate << marketprice << purchaseprice << annualinterestrate; //writing into the file
} while (totalequity = 0);
cout << "Please enter value greater than 0.";
cin >> totalequity;
while (purchaseprice = 0) ;
cout << "Please enter value greater than 0.";
cin >> purchaseprice;
while (annualinterestrate = 0) ;
cout << "Please enter value greater than 0.";
cin >> annualinterestrate;
outputFile.close(); //Closed file
ifstream inputFile;
inputFile.open("Financial_Information.txt");
outputFile.open("Menu.txt"); //opening a second file to store financial calculations
inputFile.close();
outputFile.close();
inputFile.open("Menu.txt");
//Choosing a formula
while (inputFile >> Menu)
{
//Calculations
CashFlow = income - expenses;
LeverageRatio = totaldebt / totalequity;
RealReturn = ((1 + investmentreturn) / (1 + inflationrate)) - 1;
PercentageIncrease = (marketprice - purchaseprice) / purchaseprice;
YearsToDoubleInvestment = 72 / annualinterestrate;
cout << "Enter which formula to solve;" << Menu << endl;
if (Menu == CASH_FLOW)
cout << "Cash Flow:$ " << CashFlow << endl;
elseif (Menu == LEVERAGE_RATIO)
cout << "Leverage Ratio:" << LeverageRatio << endl;
elseif (Menu == REAL_RETURN)
cout << "Real Return:" << RealReturn << endl;
elseif (Menu == PERCENTAGE_INCREASE)
cout << "Percentage Increase;" << PercentageIncrease << endl;
elseif (Menu == YEARS_TO_DOUBLE_INVESTMENT)
cout << "Years to double investment:" << YearsToDoubleInvestment << endl;
else
cout << "Exit" << endl;
}
return 0;
}
That does not produce C4700. Did you edit it after jlb's post?
Current compiler notes:
In function 'int main()':
46:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
50:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
54:33: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
19:5: warning: unused variable 'EXIT' [-Wunused-variable]
There is a difference between = and ==. Only the latter compares equality.