C++ program to calculate sales of 6 months
#include<iostream>
#include<string>
using namespace std;
void input(string *ptrMonthNamme, string *ptrSalesFig )
{
for(int i = 0; i<6; i++)
{
cout<<\n\n Enter the sales figure of "<<*ptrMonthNamme<<" : ";
cin>>*ptrSalesFig;
cout<<\t The Memory location: "<<&ptrSalesFig;
ptrSalesFig++;
ptrMonthNamme++;
}
}
double totaling(string *ptrSalesFig)
{
double sales = 0;
for(int i = 0; i<6; i++)
{
double temp = 0;
string s = *ptrSalesFig;
const char *ctemp = s.c_str();
ctemp++;
temp = atof(ctemp);
sales += temp;
ptrSalesFig++;
}
return sales;
}
void listing(string *ptrMonthNamme, string * ptrSalesFig)
{
for(int i = 0; i<6; i++)
{
cout<<\n Sales for "<<*ptrMonthNamme<<" : "<<*ptrSalesFig;
ptrMonthNamme++;
ptrSalesFig++;
}
}
int main()
{
string monthsName[] ={"Jan", "Feb", "Mar", "Apr", "May", "Jun"};
string salesFigures[6];
input(monthsName, salesFigures);
cout<< \n\n Total sales is : "<<totaling(salesFigures);
listing(monthsName, salesFigures);
return 0;
}
Output using g++ compiler