hi ..pleas any one can help me to write aprogram that allows the user to enter the last names of 5 candidates in a local election and the number of votes received by each candidate, the program should then out put each candidates name the number of vote percentage of the total votes received by the candidates received.
It should too output the winner of the election…
Write the program by using dynamic array…??
i dont understand the dynamic array very well and i wrote a code but it was wrong any one can help..

Show the code You wrote.

use the "new" keyword and have a pointer point to this new data. That's what dynamic allocation is and make the new data an array which can have any size. So may use a variable.

this is my code its work to enter the names and votes numbers but this code don't give the percentage of the votes to every candidate..


using namespace std;
double pv;
int no;
int sum=0;

void getperc(int vno[],int &sum,double pv)
    for(int i=0;i<no;i++)


void getcname(string cname[],int no)
    for(int i=0;i<no;i++)

void getvno(int vno[],int no)

    for(int i=0;i<no;i++)



int main()
string *cname;
double *perc;


cname=new string[no];

int *vno;

vno=new int[no];
perc=new double[no];


return 0;

1. Use Code Tags.
2. pv, sum, no - these are global variables, You don't need to pass them to functions.
3. Line pv=vno[i]/sum; - since both variables are integer, the result is integer as well. Thus You always get zero. Cast vno[i] to double.
4. You have memory leak. Use delete for pointers.