Skip to main content
deleted 29 characters in body
Source Link
    // 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)
{
    {
    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;
    }
}
// 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)
{
    {
    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;
    }
}
    // 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;
    }
}
added 2 characters in body; edited tags
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

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

// 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)
{
    {
    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;
    }
}**

**// 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)
{
    {
    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;
    }
}**
// 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)
{
    {
    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;
    }
}
Source Link

Pset3/Music can't check until a frown turns upside down

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)
{
    {
    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;
    }
}**