My program is not showing what i want it to.
In the data file the numbers printed were
1 1
2 2
3 3
4 4
5 5
1 5
1 4
1 3
4 5
4 2
5 1
I saved both files in the same folder and i am confused...
the numbers on top show the food and service rating. Each line counts as one customer. For example if i pick option 9, it tells me 0 people participated in the survey??
#include <iostream>
#include <fstream> //for fstream
usingnamespace std;
int main(){
ifstream infile("data.txt"); //read file into stream
int f,s;
int food[5]; //to store food rating
int service[5]; //to store service rating
int total=0,both_unsat=0,both_sat=0,both_one=0,both_5=0;
for(int i=0;i<5;i++){ //initialize all to zero
food[i]=0;
service[i]=0;
}
while(infile >> f >> s){ //read while there are entries in the file
food[f-1]++; //increment food rating
service[s-1]++; //increment service rating
total++; //total number of entries
if(f==1 && s==1){
both_one++; //both one
both_unsat++; //both unsatisfied
}
elseif(f==5 && s==5){
both_5++; //both five
both_sat++; //both satisfied
}
elseif(f<3 && s<3){
both_unsat++; //both unsatisfied
}
elseif(f>3 && s>3){
both_sat++; //both satisfied
}
}
int ch=0;
while(ch!=10){ //menu for display
cout<<"\nPlease choose a menu item."<<endl;
cout<<"1. How many customers ranked the food as satisfactory."<<endl;
cout<<"2. How many customers ranked the food as unsatisfactory."<<endl;
cout<<"3. How many customers ranked the service as satisfactory."<<endl;
cout<<"4. How many customers ranked the service as unsatisfactory."<<endl;
cout<<"5. How many customers ranked both the food and service as satisfactory."<<endl;
cout<<"6. How many customers ranked both the food and service as unsatisfactory."<<endl;
cout<<"7. How many customers ranked the food and service both as 5."<<endl;
cout<<"8. How many customers ranked the food and service both as 1."<<endl;
cout<<"9. How many customers participated in the survey."<<endl;
cout<<"10. Quit the program."<<endl;
cin>>ch;
cout<<endl;
switch(ch){
case 1: cout<<food[3]+food[4]<<" customers ranked the food as satisfactory."<<endl;
break;
case 2: cout<<food[0]+food[1]<<" customers ranked the food as unsatisfactory."<<endl;
break;
case 3: cout<<service[3]+service[4]<<" customers ranked the service as satisfactory."<<endl;
break;
case 4: cout<<service[0]+service[1]<<" customers ranked the service as unsatisfactory."<<endl;
break;
case 5: cout<<both_sat<<" customers ranked both the food and service as satisfactory."<<endl;
break;
case 6: cout<<both_unsat<<" customers ranked both the food and service as unsatisfactory."<<endl;
break;
case 7: cout<<both_5<<" customers ranked the food and service both as 5."<<endl;
break;
case 8: cout<<both_one<<" customers ranked the food and service both as 1."<<endl;
break;
case 9: cout<<total<<" customers participated in the survey."<<endl;
break;
}
}
return 0;
}