#include <iostream>
#include <iomanip>
using namespace std;
void addNodes();
void displayList();
struct vote
{
char candidate[7];
int votes;
double percent;
vote *votePtr;
};
vote *startPtr = NULL;
vote *current;
int i,j;
int main()
{
vote *startPtr = NULL;
cout<<fixed<<setprecision(0);
cout<<"Enter the number of candidates: ";
cin>>j;
addNodes();
displayList();
return 0;
}
void addNodes()
{
vote *temp, *temp2;
for(i=0;i<j;i++)
{
system("cls");
temp = new vote;
cout<<"Enter the candidate's name: ";
cin>>temp->candidate;
cout<<"Enter the votes received: ";
cin>>temp->votes;
cout<<"Enter the percentage: ";
cin>>temp->percent;
temp->votePtr = NULL; if (startPtr == NULL)
{
startPtr = temp;
current = startPtr;
}
else
{
temp2 = startPtr;
while(temp2->votePtr != NULL)
temp2=temp2->votePtr;
temp2->votePtr = temp;
}
}
return;
}
void displayList() {
vote *temp;
temp = startPtr; system("cls");
while(temp!=NULL) {
cout<<" Candidate: "<<temp->candidate<<endl;
cout<<"Votes Received: "<<temp->votes<<endl;
cout<<" Percentage: "<<temp->percent<<"%"<<endl; temp = temp->votePtr;
cout<<endl;
}
return ;
}
///WOULD I DO THAT BY DECLARING MY LOCAL VARIABLES??? I AM NOT SURE..