C++ Assignment (HELP ME PLEASE)

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.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace 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
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:";

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;
else if (Menu == LEVERAGE_RATIO)
cout << "Leverage Ratio:" << LeverageRatio << endl;
else if (Menu == REAL_RETURN)
cout << "Real Return:" << RealReturn << endl;
else if (Menu == PERCENTAGE_INCREASE)
cout << "Percentage Increase;" << PercentageIncrease << endl;
else if (Menu == YEARS_TO_DOUBLE_INVESTMENT)
cout << "Years to double investment:" << YearsToDoubleInvestment << endl;
else
cout << "Exit" << endl;

}
return 0;
}
Last edited on
but I keep getting the following error message: error C4700: uninitialized local variable 'CashFlow' used


You're calculating CashFlow after you try to print CashFlow, perhaps you need to calculate prior to printing?

First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Tags and indentation/whitespace makes your code look like this:
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace 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
    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:";
        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;
        else if (Menu == LEVERAGE_RATIO)
            cout << "Leverage Ratio:" << LeverageRatio << endl;
        else if (Menu == REAL_RETURN)
            cout << "Real Return:" << RealReturn << endl;
        else if (Menu == PERCENTAGE_INCREASE)
            cout << "Percentage Increase;" << PercentageIncrease << endl;
        else if (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.

Furthermore,
1
2
3
4
5
while ( foo ) ;
// is same as
while ( foo )
{
}
Yes, I did.
Topic archived. No new replies allowed.