problem in getting a correct name, the score is correct but it didnt match with the name..

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>[/code]
using namespace std;
const int NO_OF_CANDIDATES = 6;
void readData(ifstream& inp, string cNames[], int noofVotes[]);
void printHeading();
void printResults(string cNames[], int noofVotes[], int subS);
double getHighest(int [], int&);



int main()
{
string candidates[NO_OF_CANDIDATES];
int noofVotes[NO_OF_CANDIDATES] = {0};
ifstream infile;
int subScript = 0;
infile.open("voteData.txt");
if (!infile)
{
cout << "Input file (voteData.txt) does not exit." << endl;
return 1;
}
readData(infile, candidates, noofVotes);
printHeading();
printResults(candidates, noofVotes, subScript);
infile.close();
return 0;
}


void readData(ifstream& inp, string cNames[], int noofVotes[])
{
int cand=0;
for (cand=0; cand < NO_OF_CANDIDATES; cand++)
inp >> cNames[cand] >> noofVotes[cand];
}


void printHeading()
{
cout << " --------------Election Results--------------" << endl << endl;
cout << "Name & No. of Vote " << endl;
cout << "--------------------" << endl;
}


void printResults(string cNames[], int tVotes[], int subS)
{
int i, j;
int largestVotes = 0;
int sumVotes = 0;
for (i = 0; i < NO_OF_CANDIDATES; i++)
{
cout << cNames[i] << " ";
cout << tVotes[i] << endl;
}

cout << "--------------------" << endl;
cout << "The highest vote is " << getHighest(tVotes,subS) << endl;
cout << "The winner is " << cNames[subS] << endl;
}


double getHighest(int tVotes[], int& subscript)
{
double largest = 0;
largest = tVotes[0];
for (int i=0;i<NO_OF_CANDIDATES;i++){
if(tVotes[i]>largest){
largest=tVotes[i];

}
}
return largest;
}

Mia 34
Mickey 56
Donald 56
Danny 29
Ashley 78
Peter 56

it should give an output for Ashley instead of Mia
foo.cpp:66:38: warning: unused parameter ‘subscript’ [-Wunused-parameter]
 double getHighest(int tVotes[], int& subscript)
You have never touched `subS', ¿how do you expect it to point to the largest element?


Also, ¿why does `printResults()' ask for the `subS' parameter?
Topic archived. No new replies allowed.