C++ Programming

C++ Program to Find the Average Expenditure of the Company

Write a program  to find the average expenditure of the company for each month of each year.

Source Code

#include<conio.h>

#include<iostream>

#include<iomanip>

#define N 10

using namespace std;

int m[N][12];

int m_sum[N];

float m_avg[N];

float total;

float average;

void input(int n);

void output(int n);

int main()

{

    int n,i;

    total=0.0;

    cout<<"Enter number of years: ";

    cin>>n;

    cout<<endl<<"Enter the data:"<<endl;

    input(n);

    cout<<endl<<endl<<"The summery of data:" <<endl;

    cout<<endl<<setw(5)<<"SN"<<setw(5)<<"Jan"<<setw(5)<<"Feb"

    <<setw(5)<<"Mar"<<setw(5)<<"Apr"<<setw(5)<<"May"<<setw(5)<<"Jun"

    <<setw(5)<<"Jul"<<setw(5)<<"Aug"<<setw(5)<<"Sep"<<setw(5)<<"Oct"

    <<setw(5)<<"Nov" <<setw(5)<<"Dec"<<setw(5)<<"Avg";

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

    total=total+m_sum[i];

    average=total/12;

    output(n);

    getch();

}

void input(int n)

{

    int i, j;

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

    {

        m_sum[i]=0;

    cout<<endl<<endl<<"Year "<<i+1<<":"<<endl;

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

    {

    cout<<endl<<"Month "<<j<<": ";

    cin>>m[i][j];

    m_sum[i]+=m[i][j];

    }

    m_avg[i]=m_sum[i]/12;

    }

return;

}

void output(int n)

{

    int i;

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

    {

        cout<<endl<<setw(5)<<i+1<<setw(5)<<m[i][0]<<setw(5)<<m[i][1]

        <<setw(5)<<m[i][2]<<setw(5)<<m[i][3]<<setw(5)<<m[i][4]

        <<setw(5)<<m[i][5]<<setw(5)<<m[i][6]<<setw(5)<<m[i][7]

        <<setw(5)<<m[i][8]<<setw(5)<<m[i][9]<<setw(5)<<m[i][10]

        <<setw(5)<<m[i][11]<<setw(5)<<m_avg[i];

    }

    cout<<endl<<"Total = "<<total;

    cout<<endl<<"Average = "<<average;

    return;

}

Output

Average Expenditure of the Company

Back to top button