The following is the scenario which I had to base my program on.
Scenario
A reputable bank has asked you to create a personal finance management program. The program will need to be able to take the users monthly wage, their monthly bills, and any weekly bills that they may occur. This will then be broken down to find out how much of their wages they will then have left to save.
The user should be able to enter any amount of monthly bills and weekly bills. The user should also have the option to add other users from their household to be handled within the calculations.
Once all of the relevant information has been included, an overview of the bills against a weekly, monthly and yearly cost should be output.
Inputs
Users Name (Must be more than 1)
Monthly Wage (Must be more than 1)
The different bills the user has to pay (Per Person)
Outputs
Users Name
Weekly, Monthly, Yearly Wage Total
Weekly, Monthly, Yearly Bills Total
Total Spent on Bills
Total left to Save
10% over and under the total that can be saved
How much can be saved per month
10% over and under the total that can be saved per month
I have met all the criteria except the part where users can be dynamically added to an array. I've tried to come up with a solution but to no avail, what I have doesn't work. Does anyone know why, or does anyone know of a different approach I can take to get a working solution?
// Personal Finance Management.cpp : This file contains the 'main' function. Program execution begins and ends there. //
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
void Addusers(string *sUserName, int iArraySize)
{
for (int iCount = 0; iCount != iArraySize; iCount++)
{
cout << "\nEnter household member " << iCount + 1 << ": ";
getline(cin, sUserName[iCount]);
}
}
void AddMonthlyWage(string *sUserName, double *dMonthlyWage, const int &iArraySize)
{
for (int iCount = 0; iCount != iArraySize; iCount++)
{
cout << "\n" << "Enter monthly income for " << sUserName[iCount] << ": ";
cin >> dMonthlyWage[iCount];
}
}
void YearlyAmount(double *dYearlySalary,double *dMonthlyWage, string *sUserName, const int iArraySize)
{
for (int iCount = 0; iCount != iArraySize; iCount++)
{
dYearlySalary[iCount] = dMonthlyWage[iCount] * 12;
}
}
void WeeklyAmount(double *dYearlySalary, double *dWeeklySalary, string *sUserName, const int &iArraySize)
{
for (int iCount = 0; iCount < iArraySize; iCount++)
{
dWeeklySalary[iCount] = (dYearlySalary[iCount] /12) /4;
}
}
void BillAmounts(double *dYearlySalary, string *sUserName, double *dTotalBill, const int &iArraySize, double *dWaterBill, double *dElectricityBill)
{
const double dIncomeTax = 0.1;
for (int iCount = 0; iCount != iArraySize; iCount++)
{
cout << "\nPlease enter " << sUserName[iCount] << "'s water bill: ";
cin >> dWaterBill[iCount];
cout << "\nPlease enter " << sUserName[iCount] << "'s electricity bill: ";
cin >> dElectricityBill[iCount];
dTotalBill[iCount] = (dYearlySalary[iCount] * dIncomeTax) + dWaterBill[iCount] + dElectricityBill[iCount];
}
}
double CalculateMonthly(double dAmount)
{
double dCalculateMonthlyProcess = dAmount / 12;
return dCalculateMonthlyProcess;
}
double CalculateWeekly(double dAmount)
{
double dCalculateWeeklyProcess = dAmount / 54;
return dCalculateWeeklyProcess;
}
double MonthOver(double dAmount, double dPercentage)
{
double dPercentageUnder = dAmount + (dAmount * dPercentage);
return dPercentageUnder;
}
double TotalOverAndUnder(double dAmount, double dPercentage)
{
double dPercentageOver = dAmount + (dAmount * dPercentage);
return dPercentageOver;
}
void DisplayResults(string *sUserName, double *dMonthlyWage, double *dTotalBill, double *dYearlySalary,double *dWeeklySalary, const int &iArraySize, double *dTotalSavings, double *dPercentOver, double *dPercentUnder)
{
const double dPercentage = 0.1;
for (int iCount = 0; iCount < iArraySize; iCount++)
{
cout << "\nResults for: " << sUserName[iCount] << ".";
cout << "\nMonthly salary: £" << dMonthlyWage[iCount] << ".";
cout << "\nYearly salary is: £" << dYearlySalary[iCount] << ".";
cout << "\nWeekly salary is: £" << dWeeklySalary[iCount] << ".";
cout << "\nTotal spent on bills: £" << dTotalBill[iCount] << ".";
cout << "\nMonthly bill cost: £" << CalculateMonthly(dTotalBill[iCount]) << ".";
cout << "\nWeekly bill cost: £" << CalculateWeekly(dTotalBill[iCount]) << ".";
dTotalSavings[iCount] = dYearlySalary[iCount] - dTotalBill[iCount];
cout << "\nTotal savings: " << dTotalSavings[iCount];
dPercentOver[iCount] = dTotalSavings[iCount] + dTotalSavings[iCount] * 0.1;
cout << "\n" << dPercentage * 100 << "% over their total savings: £" << dPercentOver[iCount];
dPercentUnder[iCount] = dTotalSavings[iCount] - dTotalSavings[iCount] * 0.1;
cout << "\n" << dPercentage * 100 << "% under their total savings: £" << dPercentUnder[iCount];
cout << "\n";
}
}
//I'm trying to make a program that is dynamic and where the user will be able to enter how many family members they have and where subsequently the following arrays will have the size of what the user specified in "iArraySize".
//Does anyone know why this isn't working?
int main()
{
int iArraySize = 0;
string *sUserName = new string[iArraySize];
double *dMonthlyWage = new double[iArraySize];
double *dYearlySalary = new double[iArraySize];
double *dWeeklySalary = new double[iArraySize];
double *dTotalBills = new double[iArraySize];
//BILLS AMOUNT VARIABLES
double *dWaterBill = new double[iArraySize];
double *dElectricityBill = new double[iArraySize];
//DISPLAY RESULTS VARIABLES
double *dTotalSavings = new double[iArraySize];
double *dPercentOver = new double[iArraySize];
double *dPercentUnder = new double[iArraySize];
cout << "\nHow many members in your family?: ";
cin >> iArraySize;
//Procedure 1
Addusers(sUserName,iArraySize);
//Procedure 2
AddMonthlyWage(sUserName,dMonthlyWage,iArraySize);
//Procedure 3
YearlyAmount(dYearlySalary,dMonthlyWage, sUserName, iArraySize);
//Procedure 4
WeeklyAmount(dYearlySalary,dWeeklySalary, sUserName,iArraySize);
//Procedure 5
BillAmounts(dYearlySalary,sUserName,dTotalBills,iArraySize, dWaterBill, dElectricityBill);
//Procedure 6
DisplayResults(sUserName, dMonthlyWage,dTotalBills,dYearlySalary,dWeeklySalary, iArraySize, dTotalSavings,dPercentOver,dPercentUnder);
delete [] sUserName;
delete [] dMonthlyWage;
delete [] dYearlySalary;
delete [] dWeeklySalary;
delete [] dTotalBills;
delete [] dElectricityBill;
delete [] dTotalSavings;
delete [] dPercentOver;
delete [] dPercentUnder;
}
Aucun commentaire:
Enregistrer un commentaire