[英]Too few arguments in function
我正在写一个函数getIntLimited,该函数只能在某个最大值和最小值之间的数字除外。 目前没有分配的最大值或最小值,但是代码本质上仍应起作用。 但是,我似乎收到一个错误消息,指出函数中的参数太少,但是我不确定为什么会这样。 这是我的代码:
#include <stdio.h>
#include <stdlib.h>
//tools
void welcome(void);
void printTitle(void);
void printFooter(double gTotal);
void flushKeyboard(void);
void pause(void);
int getInt(void);
double getDouble(void);
int getIntLimited(int lowerLimit, int upperLimit);
//app interface
int yes(void);
void GroceryInventorySystem(void);
int menu(void);
int main(void){
int iVal;
double dVal;
welcome();
printTitle();
double grandtotal = 1234.57;
printFooter(grandtotal);
flushKeyboard();
pause();
getInt();
int lowLimit;
int upLimit;
getIntLimited(int lowLimit, int upLimit);
return 0;
}
//code your functions here:
void welcome(void)
{
printf("---=== Grocery Inventory System ===---");
printf("\n");
return;
}
void printTitle(void)
{
printf("Row |SKU| Name | Price |Taxed| Qty | Min | Total |Atn\n");
printf("----+---+---------------+-------+-----+-----+-----+-------------|---");
printf("\n");
return;
}
void printFooter(double grandTotal)
{
printf("--------------------------------------------------+-----------------");
printf("\n");
if (grandTotal > 0) {
printf(" Grand Total: | %12.2lf", grandTotal);
}
printf("\n");
return;
}
void flushKeyboard(void)
{
int read;
while (( read = getchar()) != '\n')
return;
}
void pause(void)
{
printf("Press <ENTER> to continue...\n");
flushKeyboard();
return;
}
int getInt(void)
{
int Value;
char NL = 'x';
while (NL != '\n') {
scanf("%d%c", &Value, &NL);
if (NL != '\n') {
flushKeyboard();
printf("Invalid integer, please try again: \n");
}
}
return Value;
}
int getIntLimited(int lowerLimit, int upperLimit)
{
int limit;
do {
limit = getInt();
if(lowerLimit > limit || limit > upperLimit) {
printf("Invalid value, %d < %d < %d: ", lowerLimit, limit, upperLimit);
}
}
while(lowerLimit < limit && limit < upperLimit);
return limit;
}
在您的main
函数中,这不是函数调用:
getIntLimited(int lowLimit, int upLimit);
摆脱int
关键字:
getIntLimited(lowLimit, upLimit);
另外,请注意,将lowLimit
和upLimit
传递给getIntLimited
时,它们不会初始化。 读取未初始化的值会调用未定义的行为。
getIntLimited(int lowLimit,int upLimit); 而不是使用getIntLimited(lowLimit,upLimit); 因为在函数调用期间不需要数据类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.