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(¬e[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(¬e[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;
}
}
expected exit code 0, not 1
)