我试过并搜索了所有内容,但我似乎无法解决这些神秘的错误。在我的helpers.c文件中,它说我没有使用任何参数,尽管我已经使用了所有参数。
以下是我得到的错误:
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.
这是我的代码:
//帮助音乐功能
#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;
}
我仍在按照课程说明推荐我的功能(一步一步),但我甚至无法编译以查看我所做的任何事情是否正确。
我不明白为什么我没有“使用参数”我可以指出的另一件事是我的错误给了我(看似)不正确的位置。这是否意味着IDE / compiler / makefile出现了问题?
这几天我一直在为此而自杀。任何帮助将非常感激。提前谢谢你。