Here I'm trying to write a c programming below,Here I created a data type person which has two arguments name and number (creating a name of the candidate and votes they have recieved), and when prompt for input,if user enters the name in the array of person data_type and number corresponds to that number should increase,but I got stuck in this error below.
#include<stdio.h>
#include<cs50.h>
#include<string.h>
//Making person variable
typedef struct
{
string name;
int number;
}
person;
int update_vote(string name,person arr);
int main(void)
{
person cand[4];
cand[0].name="Brian";
cand[1].name="David";
cand[2].name="Obama";
cand[3].name="Biden";
cand[0].number=0;
cand[1].number=0;
cand[2].number=0;
cand[3].number=0;
//print the candidate names on the screen
float len=sizeof(cand)/sizeof(cand[0]);
int yu =(int) len;
printf("Candidates Who are participating:");
printf("\n");
for (int i=0;i<yu;i++)
{
printf("%i.%s ",i+1,cand[i].name);
}
printf("\n");
//prompt for voters and take votes and update
int voters=get_int("Enter the number of voters:");
for (int j=0;j<voters;j++)
{
string vote=get_string("Enter your vote:");
int update=update_vote(vote,cand);
if (update!=-1)
{
cand[update].number++;
}
else{
printf("Invalid name entered");
}
}
printf("%d",cand);
}
int update_vote(string name,person arr)
{
float len=sizeof(arr)/sizeof(arr[0]);
int yu =(int) len;
for(int i=0;i<yu;i++)
{
if (strcmp((name,arr[i].name)==0))
{
return i;
}
}
return -1;
}
But got stuck in figuring out why the error is occuring below
error: passing 'person [4]' to parameter of incompatible type 'person' int update=update_vote(vote,cand);