0

Please I'm getting this error when I try to submit pset3.

expected exit code 0, not 1

My code for synthesizing works fine and I'm able to play wav files from text files.

I'm not sure if it's ok for me to post my code here but here's my code for the problem set. If it's not ok I'll take down this post. Thanks in advance!

// Helper functions for music

#include <cs50.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "helpers.h"

// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
    // TODO
    double numerator = atoi(&fraction[0]);
    double denominator = atoi(&fraction[2]);

    // calculate duration of note
    double duration = (numerator / denominator) / 0.125;

    return round(duration);
}

// Calculates frequency (in Hz) of a note
int frequency(string note)
{
    // TODO
    // length 3 to accomodate for the terminating character
    // string music_note;
    char music_note[3];
    int octave;
    // get length of note
    if (strlen(note) == 2)
    {
        // e.g. if note is A4, note = A
        music_note[0] = note[0];
        music_note[1] = '\0';

        // get octave i.e. A4 octave => 4
        octave = atoi(&note[1]);
    }
    else
    {
        // e.g. if note is A#4 note = A#
        music_note[0] = note[0];
        music_note[1] = note[1];
        music_note[2] = '\0';

        // get octave
        octave = atoi(&note[2]);
    }

    // printf("Note: %s\n", note);
    printf("Music note: %s\n", music_note);

    // best case if octave is 0 return base frequency
    if (octave == 0)
    {
        return get_base_frequency(music_note);
    }
    else
    {
        double base_frequency = get_base_frequency(music_note);

        // multiply base_frequency by 2 ^ octave to get frequency of note in octave
        return round(base_frequency * pow(2, octave));
    }
}

// Determines whether a string represents a rest
bool is_rest(string s)
{
    // TODO
    if (strcmp(s, "") == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

// take a string note and gets the base frequency in the 0th octave
// it's still kinda like the A440 standard
// eg 'A' => 27, 'A#' => 29 etc
// frequencies returned are based on the 0th octave
double get_base_frequency(string note)
{
    if (strcmp(note, "C") == 0)
    {
        return 16.35;
    }
    else if (strcmp(note, "C#") == 0 || strcmp(note, "Db") == 0)
    {
        return 17.32;
    }
    else if (strcmp(note, "D") == 0)
    {
        return 18.35;
    }
    else if (strcmp(note, "D#") == 0 || strcmp(note, "Eb") == 0)
    {
        return 19.45;
    }
    else if (strcmp(note, "E") == 0)
    {
        return 20.60;
    }
    else if (strcmp(note, "F") == 0)
    {
        return 21.83;
    }
    else if (strcmp(note, "F#") == 0 || strcmp(note, "Gb") == 0)
    {
        return 23.12;
    }
    else if (strcmp(note, "G") == 0)
    {
        return 24.50;
    }
    else if (strcmp(note, "G#") == 0 || strcmp(note, "Ab") == 0)
    {
        return 25.96;
    }
    else if (strcmp(note, "A") == 0)
    {
        return 27.50;
    }
    else if (strcmp(note, "A#") == 0 || strcmp(note, "Bb") == 0)
    {
        return 29.14;
    }
    else if (strcmp(note, "B") == 0)
    {
        return 30.87;
    }
    else
    {
        // indicates note entered was an unknown note
        return 99999.0;
    }
}
2
  • Could show the rest of the error message? (the lines just above expected exit code 0, not 1) Commented Oct 25, 2018 at 18:40
  • This is the error => running clang -std=c11 -o is_rest is_rest.c wav.c helpers.c -lcs50 -lm... checking that program exited with status 0... @PeterPesch Commented Oct 25, 2018 at 18:45

1 Answer 1

1

You say that your submission failed at this point:

:( helpers.c compiles
Log
running clang -std=c11 -o is_rest is_rest.c wav.c helpers.c -lcs50 -lm... 
checking that program exited with status 0...  
expected exit code 0, not 1

That means that it failed at the compilation of is_rest.c (I guess that's one of the programs they use to test your code) with helpers.c.


As far as I can see, submissions for this pset will only upload 2 files: bday.txt and helpers.c

Now I see that your function frequency() uses get_base_frequency().

However, that function is only defined at the bottom of your file.

I cannot see the declaration of that function in helpers.c, so you apparently added that into helpers.h - which unfortunately is not uploaded during the submission ...

If you move the declaration of get_base_frequency() from helpers.h to helpers.c, the check should pass this step.


Finally, to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • That worked! Thanks a lot @PeterPesch Commented Oct 25, 2018 at 19:45

You must log in to answer this question.

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