I tired compiling my code, many time but it shows :( tideman compiles code failed to compile. Can anyone take a look. Another thing that i want to ask is my code well written? Because i feel it's too long
#include <stdio.h>
#include <cs50.h>
#include <string.h>
typedef struct
{
string rank_1;
string rank_2;
string rank_3;
}
ballot;
int vote_count(int count, int size, ballot vote[size], string name);
int max(int n, int arr[n]);
int main(int argc, string argv[])
{
int len = get_int("No. of votes : ");
ballot vote[len];
for (int i = 0; i < len ; i++)
{
vote[i].rank_1 = get_string("Rank 1 : ");
vote[i].rank_2 = get_string("Rank 2 : ");
vote[i].rank_3 = get_string("Rank 3 : ");
printf("\n");
}
int array[argc - 1];
for (int i = 0; i < argc - 1; i++)
{
int count = 0;
array[i] = vote_count(count, len, vote, argv[i + 1]);
}
printf("Result : %d %d %d\n", array[0], array[1], array[2]);
int alpha = max(argc - 1, array);
return 0;
}
int vote_count(int count, int size, ballot vote[size], string name)
{
for (int j = 0; j < size; j++)
{
if (strcmp(vote[j].rank_1, name) == 0)
{
count += 3;
}
else if (strcmp(vote[j].rank_2, name) == 0)
{
count += 2;
}
else if (strcmp(vote[j].rank_3, name) == 0)
{
count += 1;
}
else
{
count += 0;
}
}
return count;
}
int max(int n, int arr[n])
{
int check = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > check)
check = arr[i];
return check;
}