My code doesn't display array values that I input, instead it only prints zero. It supposed to print the values if I choose case 2 after completing the case 1. My code doesn't display array values that I input, instead it only prints zero. It supposed to print the values if I choose case 2 after completing the case 1.
#include <iostream>
using namespace std;
int main(){
string candidate[4];
int a[5], b[5], c[5], d[5];//precint
int total;
int choice;
char yesNo;
int i;
do{
cout<<"[1] Enter candidates names and votes"<<endl;
cout<<"[2] Show Tally"<<endl;
cout<<"[3] Exit"<<endl;
cout<<"Enter a choice: ";
cin>>choice;
switch(choice){
case(1):
for(int i=0; i<4; i++){
cout<<"Enter candidate names: ";
cin>>candidate[i];}
for(int i=0; i<5; i++){
cout<<"Candidate "<<candidate[0]<<" precinct "<<i+1<<" votes: ";
cin>>a[i];
}
for(int i=0; i<5; i++){
cout<<"Candidate "<<candidate[1]<<" precinct "<<i+1<<" votes: ";
cin>>b[i];
}
for(int i=0; i<5; i++){
cout<<"Candidate "<<candidate[2]<<" precinct "<<i+1<<" votes: ";
cin>>c[i];
}
for(int i=0; i<5; i++){
cout<<"Candidate "<<candidate[3]<<" precinct "<<i+1<<" votes: ";
cin>>d[i];
}
break;
case(2):
cout<<"Precinct\tCandidate: "<<candidate[0]<<"\tCandidate: "<<candidate[1]<<"\tCandidate: "<<candidate[2]<<"\tCandidate: "<<candidate[3]<<endl;
for(int j=1; j<6;j++)
cout<<j<<"\t\t"<<a[i]<<"\t\t"<<b[i]<<"\t\t"<<c[i]<<"\t\t"<<d[i]<<endl;
break;
}
cout<<"Do you want to continue(Y/N): ";
cin>>yesNo;
}while (yesNo == 'y' || yesNo == 'Y');
cout<<"Thank You!";
return 0;
}
iis uninitialized when you print a/b/c/d