I have tried and googled everything, but I cannot seem to fix these mysterious errors. Within my helpers.c file, it is saying that I haven't used any of the parameters although I've used all of them.
Below are the errors I'm getting:
helpers.c:8:21: error: unused parameter 'fraction' [-Werror,-Wunused-parameter] int duration(string fraction) ^ helpers.c:11:1: error: control reaches end of non-void function [-Werror,-Wreturn-type] } ^
helpers.c:14:22: error: unused parameter 'note' [-Werror,-Wunused-parameter] int frequency(string note) ^
helpers.c:17:1: error: control reaches end of non-void function [-Werror,-Wreturn-type] } ^
helpers.c:20:21: error: unused parameter 's' [-Werror,-Wunused-parameter] bool is_rest(string s) ^
helpers.c:23:1: error: control reaches end of non-void function [-Werror,-Wreturn-type] } ^
6 errors generated.
Here is my code:
// Helper functions for music
#include <cs50.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "helpers.h"
// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
// convert string input to int
int x = fraction[0] - '0';
int y = fraction[2] - '0';
// convert to integral number of eighths
if (y == 8)
{
return x;
}
return (8 / y) * x;
}
// Calculates frequency (in Hz) of a note
int frequency(string note)
{
// Parse string <note> //not quite sure on data types (chars or int?)
int baseHz = 440; //A4's Hz
char letter = note[0];
if (strlen(note) < 3) //notes with # or b
{
int octave = note[1] - '0';
}
else //notes without # or b
{
int octave = note[2] - '0';
}
//find distance from octave 4
int octave_dist = octive - 4; //power of 2 for octave adjustment
//multiplier to adjust for octave
int octave_adjust = pow(2, octave_dist); //not sure on types here??
//find note distance from A
float n = 2.0; //number of semitones between notes
if (letter != 'B') //B will use default n = 2
{
n = ('A' - letter) * 2;
}
//multiplier to adjust for note
float note_adjust = pow(2, n/12.0);
//multiplier to adjust for # or b
int Hz = round(baseHz * octave_adjust * note_adjust);
return Hz;
}
// Determines whether a string represents a rest
bool is_rest(string s)
{
//get_string return "" if user input is only a line ending
if (strcmp(s, "") == 0)
{
return true;
}
return false;
}
I'm still working on my functions (step by step) as recommended by course instructions, but I can't even compile to see if anything I've done is correct.
I don't understand why I haven't "used the parameters" Another thing I can point out is that my errors are giving me the (seemingly) incorrect locations. Could this mean there is something wrong with the IDE/compiler/makefile?
I've been killing myself over this for days. Any help would be HUGELY appreciated. Thanks you in advance.
helpers.c
in the ZIP file, each function contains only// TODO
, but noreturn
. Did you forget to save? Did you save under another name or in another directory?