0

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;
}
2
  • This looks like the result of check50, not of actually trying to compile the program. Did you run `make tideman'? Please edit the question and post the result of running make. You should also spend some quality time with style50 to learn how to properly indent.
    – Cliff B
    Commented Aug 11, 2021 at 12:06
  • 1
    From the spec: "You should not modify anything else in tideman.c other than the implementations of the vote, record_preferences, add_pairs, sort_pairs, lock_pairs, and print_winner functions". Make sure you start with the distro code tideman.c as per the spec. Commented Aug 11, 2021 at 18:01

1 Answer 1

0

So the code run & compiles well manually, but it shows failed to complies on check50. Reasons maybe Check50 is only taking a specified format of code that given in Pset3. Like Check50 is looking of those functions (record_preference, add_pairs, sort_pairs, lock_pairs, .... which aren't there in tideman code provided above.

1
  • This is the answer. When you are able to, please accept this to close out this question. DinoCoderSaurus provided this (the answer) in his comment to your question. Whenever CS50 provides you structure to your code, you are not supposed to change that structure, and the spec will tell you this. Commented Aug 12, 2021 at 11:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .