hello I have the following program in which there is a switch menu and when a person enters 2 the switch menu should take to the second function which is funcTwo but it is not doind so and just gets back to the menu it self i tried switching the function that is i called function one in case two and it worked fine but calling function two in case 2 isnt working or for that matter calling function 2 in switch two isnt working either can some one please help me with this problem.
thankyou`
// sharyar khalid
// sample lab 8A
// 0253
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct survey
{
string code;
double income;
int members;
};
void funcOne(survey w[]);
void funcTwo(survey w[]);
ifstream infile;
ofstream outfile;
int main()
{
int choice;
survey w[16];
survey dw[16];
infile.open ("E:\\lab8adatafile.txt");
if (!infile)
{
cout<<"Cannot open file, terminating program"<<endl;
system ("pause");
return 0;
}
outfile.open("E:\\lab8arun.txt");
while(!infile.eof())
{
for(int i=0; i<16;i++)
{
infile>>w[i].code>>w[i].income>>w[i].members;
}
for(int m=0;m<16;m++)
{
dw[m]=w[m];// here is where I copy the struct w to struct dw to sort.
}
}
do
{
cout<<endl;
cout<<"MENU"<<endl;
cout<<"1. Print all of the input data with appropriate column headings. "<<endl;
cout<<"2. Calculate the average household income and list the identification "<<endl;
cout<<" codes and income of each household whose income is greater than the average. ";
cout<<"3. Determine the percentage of households having an income below the poverty "<<endl;
cout<<"4. Print all of the input data sorted by household income "<<endl;
cout<<"5. Calculate and print the median household income "<<endl;
cout<<"6. Exit";
cout<<"\n\nEnter your choice 1-6 :";
cin>>choice;
switch(choice)
{
case 1:{cout<<endl;
funcOne(w);}
break;
case 2: funcTwo(w);
break;
}
}while(choice!=6);
return 0;
}
/***************************************/
void funcOne (survey w[])
{
cout<<setw(11)<<" CODE "<<setw(11)<<" INCOME "<<setw(10)<<" MEMBERS "<<endl<<endl;
for(int i=0; i<16;i++)
{
cout<<setw(10)<<w[i].code<<setw(10)<<w[i].income<<setw(10)<<w[i].members<<endl;
}
}
/***************************************/
void funcTwo (survey w[])
{
double sum=0;
double avg=0;
int count=0;
for(int i=0;i<count;i++) // Outputs the numbers in both Arrays.
{
sum=sum+w[i].income;
cout<<" This is the sum of all the household income "<<sum<<endl;
}
}
Inline Code Example Here`