pset3 Music design and connection to Week 2 lecture?

I have completed all of the work for pset3 Music and it works fine. There are no error messages, I can synthesize the songs, and it passes all the Check50 tests. However I can't shake this nagging feeling that my code is not designed well, especially for the frequency function. There must be a more efficient way to write this code than what I have done.

I am also having a very tough time connecting the solutions for this problem to the topics discussed in the Week 2 lecture. They seem to be disconnected. Are there any ways to use the sorting concepts or recursion that David discussed in this problem?

Here is my code for the helpers functions:

// Helper functions for music

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

#include "helpers.h"

// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
int result;
int n = fraction - '0';
int d = fraction - '0';

result = 8 * n / d;

return result;

}

// Calculates frequency (in Hz) of a note
int frequency(string note)
{
//set variables
float hertz = 440;
char key;
int accidental = 0;
char octave;
int o = 0;

//save note letter as key
key = toupper(note);
key = '\0';

//save accidentals and octaves
if (note == '#')
{
accidental = 1;
octave = note;
}
else if (note == 'b')
{
accidental = -1;
octave = note;
}
else
{
octave = note;
}

octave = '\0';

o = atoi(octave) - 4;
hertz = hertz * pow(2, o);

hertz = hertz * pow(2, (accidental / 12.0));

//value for keys
if (key == 'B')
{
}

if (key == 'C')
{
}

if (key == 'D')
{
}

if (key == 'E')
{
}

if (key == 'F')
{
}

if (key == 'G')
{
}

hertz = hertz * pow(2, (adjust / 12.0));

//return
return round(hertz);

}

// Determines whether a string represents a rest
bool is_rest(string s)
{
if (strcmp(s, "") == 0)
{
return true;
}
else
{
return false;
}
}
• Not really a use for a sort algorithm in this one, although it is an important tool in programming. As for program efficiency, well, think about it for a week. You'll figure out better ways! ;-) Jul 24 '18 at 4:51

If you allow me, I have a suggestion or two:

• Keys, Octaves and Accidentals can be char rather than an array of char since they are always one character only. So instead of representing each of them as an array of char where the second element is a \0 just char octave = note[strlen(note) - 1] will always give you the last character of the note, which is always the octave.
• Same with key... char key = note will always be the key of any note.

• Instead of multiple if statements, a switch could be cleaner and easier to read:

switch(key) {
case(key == 'B'):