I've been working on my music code for quite some time now, and keep running into the same issue. Whenever I try to compile my code, I get "unused parameter" and "control reaches end of non-void function" errors. From my online searches, these errors have to do with the function possible not returning anything at all, while it's been declared as a non-void function. I haven't been able to see this in my code though, as I thought I covered all possible scenario's.
I tried using Help50, but this didn't give me much more information ("Ensure that you function will always return a value")
Any help would be greatly appreciated! FYI, this is just my is_rest and duration code, as I wanted to fully understand these parts first before diving into frequency.
int duration(string fraction)
{
// Variable f for converting third element of fraction
int result;
int f;
f = atoi (fraction[2]);
// If numerator is 1, assign results for subsequently denominators 8/4/2/1
for (fraction[0] == 1)
{
if (f == 8)
{
result = 1;
}
else if (f == 4)
{
result = 2;
}
else if (f == 2)
{
result = 4;
}
else if (f == 1)
{
result = 8;
}
}
// Check for numerator = 3 and denominator = 4
for (fraction[0] == 3)
{
if (f == 4)
{
result = 6;
}
else
{
return 0;
}
}
// Output result
return result;
}
// Determines whether a string represents a rest
bool is_rest(string s)
{
if (s[0] == '"')
{
return true;
}
else if (s[0] != '"')
{
return false;
}
}
----- EDIT: new code per 2/27/2018 ------
// Converts a fraction formatted as X/Y to eights
int duration(string fraction)
{
// Variable f for converting third element of fraction into integer
int result;
int f;
f = atoi (fraction[2]);
// If numerator is 1, assign results for subsequently denominators 8/4/2/1
if (fraction[0] == 1)
{
if (f == 8)
{
result = 1;
}
else if (f == 4)
{
result = 2;
}
else if (f == 2)
{
result = 4;
}
else if (f == 1)
{
result = 8;
}
else
{
return 1;
}
}
// Check for numerator = 3 and denominator = 4
else if (fraction[0] == 3)
{
if (f == 4)
{
result = 6;
}
else
{
return 1;
}
}
else
{
return 1;
}
// Output result
return result;
}
// Determines whether a string represents a rest
bool is_rest(string s)
{
if (s[0] == '"')
{
return true;
}
else if (s[0] != '"')
{
return false;
}
return true;
}