0% found this document useful (0 votes)
21 views

SWE DA1 Code

This document contains code to calculate financial metrics like net present value, return on investment, and discounted cash flows for multiple projects. It prompts the user to input cash flows for different projects and years, then calculates metrics like net profit, average profit, ROI, discount factors, and NPV for each project.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

SWE DA1 Code

This document contains code to calculate financial metrics like net present value, return on investment, and discounted cash flows for multiple projects. It prompts the user to input cash flows for different projects and years, then calculates metrics like net profit, average profit, ROI, discount factors, and NPV for each project.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

#include<stdio.h>

#include<math.h>

int main()

{int n,y,i,j,k,a[5][10];

float netprofit[5],avgprofit[5],roi[5];

double discountfactor[5][10],discountedcashflow[5][10],npv[5];

std::cout<<"\nEnter the number of projects\n";

std::cin>>n;

std::cout<<"\nEnter the number of years\n";

std::cin>>y;

for(i=0;i<n;i++)

{ std::cout<<"\n Enter the cash flow for project "<<i;

std::cout<<"\n Enter the initial investment ";

std::cin>>a[i][0];

for(j=1;j<=y;j++)

{ std::cout<<"\n Enter the value for year "<<j<<" ";

std::cin>>a[i][j];

for(i=0;i<n;i++)

{ netprofit[i]=0;

for(j=1;j<=y;j++)

netprofit[i]+=a[i][j];

netprofit[i]-=a[i][0];

}
for(i=0;i<n;i++)

std::cout<<"Net profit for project "<<i+1<<" is "<<netprofit[i]<<"\n";

for(i=0;i<n;i++)

{ avgprofit[i]=netprofit[i]/y;

std::cout<<"\n Average annual profit for project "<<i+1<<" is "<<avgprofit[i];

for(i=0;i<n;i++)

{ roi[i]=(avgprofit[i]/a[i][0])*100;

std::cout<<"\n ROI for project "<<i+1<<" is "<<roi[i];

for(i=0;i<n;i++)

{ std::cout<<"\n \nDiscount factors for project "<<i+1<<"\n";

for(j=0;j<=y;j++)

{ double x=pow(1.15,j);

discountfactor[i][j]=1/x;

std::cout<<"\n Discount factor for year "<<j<<" is "<<discountfactor[i][j];

for(i=0;i<n;i++)
{ for(j=0;j<=y;j++)

discountedcashflow[i][j]=discountfactor[i][j]*a[i][j];

for(i=0;i<n;i++)

{ npv[i]=0;

for(j=1;j<=y;j++)

npv[i]+=discountedcashflow[i][j];

npv[i]=npv[i]-discountedcashflow[i][0];

std::cout<<"\n NPV for project "<<i+1<<" is "<<npv[i];

return 0;

You might also like