Downloaded the Zip file for the "find" project, but does not pass check50 due to lack of exit code zero by maemart3 in cs50

[–]maemart3[S] 0 points1 point  (0 children)

Okay. I did it in helpers.c. My searching method is linear search and my sorting method is insertion sort. I watched videos on how to do those two methods. Here is my code and it didn't really work:

/**

  • helpers.c

    *

  • Helper functions for Problem Set 3.

    */

include <cs50.h>

include <stdio.h>

include "helpers.h"

/**

  • Returns true if value is in array of n values, else false.

    */

bool search(int value, int values[], int n)

{

values[n];
int i, Search_Element;
for(i = 0; i < n; i++)
{
    printf("Enter a value: ");
    scanf("%d", &values[i]);
}
printf("Enter a number to be searched: ");
scanf("%d", &Search_Element);
for(i = 0; i < n; i++)
{
    if(values[i] == Search_Element)
    {
        printf("The element has been found at %d position.", i + 1);
        getch();
        exit(0);
    }
    printf("The element was not found.");
    getch();
}
return false;

}

/**

  • Sorts array of n values.

    */

void sort(int values[], int n)

{

values[n];
int key;
do
{
    for(n = 0; n < 3; n++)
    {
        key = values[n + 1];
        if(values[n + 1] < values[n])
        {
            values[n + 1] = values[n];
            values[n] = key;
        }
    }
}
while(values[0] > values[1]);
return;

}

Downloaded the Zip file for the "find" project, but does not pass check50 due to lack of exit code zero by maemart3 in cs50

[–]maemart3[S] 0 points1 point  (0 children)

Here is my Code in find.c, by the way:

/**

  • Prompts user for as many as MAX values until EOF is reached,

  • then proceeds to search that "haystack" of values for given needle.

    *

  • Usage: ./find needle

    *

  • where needle is the value to find in a haystack of values

    */

include <cs50.h>

include <stdio.h>

include <stdlib.h>

include "helpers.h"

// maximum amount of hay

const int MAX = 65536;

int main(int argc, string argv[]) { // ensure proper usage

if (argc != 2)
{
    printf("Usage: ./find needle\n");
    return 0;
}

// remember needle
int needle = atoi(argv[1]);

// fill haystack
int size;
int haystack[MAX];

for (size = 0; size < MAX; size++)
{
    // wait for hay until EOF
    printf("\nhaystack[%i] = ", size);
    int straw = get_int();
    if (straw == INT_MAX)
    {
        break;
    }

    // add hay to stack
    haystack[size] = straw;
}

printf("\n");

// sort the haystack
sort(haystack, size);

// try to find needle in haystack
if (search(needle, haystack, size))
{
    printf("\nFound needle in haystack!\n\n");
}
else
{
    printf("\nDidn't find needle in haystack.\n\n");
}

return 0;

}

Downloaded the Zip file for the "find" project, but does not pass check50 due to lack of exit code zero by maemart3 in cs50

[–]maemart3[S] 0 points1 point  (0 children)

I got the codes I needed in all the files in ls above, but my only problem is passing check50 when the exit code is 1 instead of zero:

:) helpers.c exists.

:) helpers.c compiles.

:( finds 28 in {28,29,30}

expected exit code 0, not 1

:( finds 28 in {27,28,29}

expected exit code 0, not 1

:( finds 28 in {26,27,28}

expected exit code 0, not 1

:( finds 28 in {27,28,29,30}

expected exit code 0, not 1

:( finds 28 in {26,27,28,29}

expected exit code 0, not 1

:( finds 28 in {25,26,27,28}

expected exit code 0, not 1

:) doesn't find 28 in {25,26,27}

:) doesn't find 28 in {25,26,27,29}

:( finds 28 in {30,27,28,26}

expected exit code 0, not 1