# Pset3 Music - "unused parameter" and "reaching end of non-void function"

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;
}
``````

`````` for (fraction[0] == 1)
``````

This is an incorrect use of a loop, I think it worthwhile to read thoroughly about the for loops, you have a boolean value within a for loop that is effectively not used. Maybe you wanted an IF comparison?

As for your function is_rest does not return any value even if you do not believe it, the return statement must not be in a conditional block as you do, because at compile time the compiler has no way of "knowing" what value is going to return, the solution would be to put a return statement by default at the end of the function:

``````bool is_rest(string s)
{
if (s[0] == '"')
{
return true;
}
else if (s[0] != '"')
{
return false;
}
return false; // or true
}
``````
• thanks so much for your reply. I used your comments and changed my code, but still seem to come across the same issues. For int_duration, I changed the condition to an if-statement. I also added return 1 statements for values that should not be accepted (i.e. if numerator is neither 1 nor 3) and a 'catch-all' return statement outside the condition block. For int_rest, I followed your example and added a 'catch-all' return statement outside the condition block. I added my new code above, below the original code. I also added a screenshot of the errors. Again, thanks! Feb 27 '18 at 17:27
• I really do not appreciate any obvious error, be sure to save the changes before compiling. If your problems persist open a new question, it is easier to answer among all.
– MARS
Feb 28 '18 at 12:10