0

i got this message when i tried to check50 of music problem "can't check until a frown turns upside down", i couldn't find what is cause of the problem, so i'll be thankful if someone give me a hand

    // Helper functions for music
#include <cs50.h>
#include <stdio.h>
#include "helpers.h"
#include <math.h>
#include <string.h>

// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
    int nom = fraction[0] - 48;
    int dom = fraction[2] - 48;
    int num = (8 * nom) / dom;
    return num;
}


// Calculates frequency (in Hz) of a note

int frequency(string note)
{
    note = get_string();
    int note_letter = note [0];
    int octave = note [strlen(note) - 1] - '0';
    unsigned int move_octave = octave - 4;
    float freq = 440;
    char semi = note [1];
    float a = 0.0, b = 1.0, c = -9.0, d = -7.0, e = 5.0, f = 4.0, g = 2.0;
    float n = 0;

    freq *= (pow(2, move_octave));

    switch(note_letter)
    {
        case 'A':
            n = a;
            break;
        case 'B':
            n = b;
            break;
        case 'C':
            n = c;
            break;
        case 'D':
            n = d;
            break;
        case 'E':
            n = e;
            break;
        case 'F':
            n = f;
            break;
        case 'G':
            n = g;
            break;
    }

    freq *= pow(2.0, n/12.0 );

    if (semi == 'b')
    {
        freq /= (powf(2.0, (1.0/12.0))); //b lower semitone
    }
    else if (semi == '#')
    {
        freq *= (powf(2.0, (1.0/12.0))); //# higher semitone
    }
    freq = round(freq);

    return freq;
}

// Determines whether a string represents a rest
bool is_rest(string s)
{
    string rest = s;
    char new_line = '\n';

    if (strcmp (rest, &new_line) == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
0

1 Answer 1

0

Did you actually compile the program before trying to run check50? When I ran it, there were several compile errors. You need to compile, run and test the program and debug it before running check50.

All of the compile errors need to be resolved before you do anything else. Work through them in order. Sometimes one error is the cause of multiple errors that follow.

This will be good practice for you. One of the most important skills in programming is the ability to debug code and resolve these problems. Besides, what are you going to do when you're writing your own code and there's no check50 to be found? ;-)

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

1
  • thanks for your answer, i don't know how to debug the files in this problem, anyway i've corrected the errors that i made and i got a new error with check50 here it is if you could take a look cs50.stackexchange.com/questions/28580/…
    – Sengo
    Commented Mar 18, 2018 at 4:21

You must log in to answer this question.

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