Trying to write the below program and having a problem compiling. Getting the following error: Line 27 conversion from `std::string*' to non-scalar type `std::string' requested .
Really need help as have to have this program done for tomorrow. Anyone any suggestions?
Thanks!
//Election results//
#include <iostream>
#include <cstring>
using namespace std;
const int ward=10;
void read_votes (int votes[][ward], string names[], int size);
void read_names (string names[], int max_size, string sentinel, int& size);
int search (string names[], string key, int size);
void total_votes (int totals[], int votes[][ward], int size);
void print_results (string names, int votes[][ward], int totals[], int size);
int main(){
const int MAX_SIZE=50;
const string sentinel= "xxx";
int size=0;
string names[MAX_SIZE];
int votes[MAX_SIZE][ward];
int totals[MAX_SIZE];
read_names (names, MAX_SIZE, sentinel, size);
read_votes (votes, names, size);
total_votes (totals, votes, size);
print_results (names, votes, totals, size);
system ("PAUSE");
return 0;
}
//void read_votes (double votes[]ward[], string candidate_name){
void read_names (string names[], int max_size, string sentinel, int& act_size){
int i=0;
string n;
cin>>n;
while (i < max_size && n!= sentinel){
names[i]=n;
i++;
act_size++;
cin>>n;
}
return;
}
int search (string names[], string key, int size){
for (int i=0; i<size; i++){
if (names[i]== key)
return i;
else return -1;
}
}
void read_votes (int votes[][ward], string names[], int size){
int ward;
cin>>ward;
while (ward != -1){
if (ward<=10){
string test_name;
cin>> test_name;
int p= search (names, test_name, size);
if (p == -1){
cout<<"Error: Name not amoung candidates"<<endl;
return;}
int num_votes;
cin>>num_votes;
votes[p][ward]=num_votes;
}
else{
cout<<"Error: invalid ward"<<endl;
return;}
cin>>ward;
}
return;
}
void total_votes (int totals[], int votes[][ward], int size){
for (int a=0; a<size; a++){
for (int i=0; i<size; i++){
for (int j=0; j<ward; j++)
totals[a]=votes[i][j];
}
}
return;
}
void print_results (string names, int votes[][ward], int totals[], int size){
cout<<" ";
for (int b=1; b<=10; b++)
cout<<"b"<<" ";
cout<<" "<<"TOTAL"<<endl;
for (int a=0; a<size; a++){
for (int n=0; n<size; n++){
cout<<names[n]<<" ";
for (int i=0; i<size; i++){
for (int j=0; j<ward; j++){
cout<<votes[i][j]<<" ";
cout<<endl;
}
}
}
cout<<totals[a];
}
return;
}
This post has been edited by TrinLH: 27 April 2009 - 12:14 PM

New Topic/Question
Reply




MultiQuote






|