Jin*_*nto 0 c parameters arguments 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;
}
Run Code Online (Sandbox Code Playgroud)
在您的main函数中,这不是函数调用:
getIntLimited(int lowLimit, int upLimit);
Run Code Online (Sandbox Code Playgroud)
摆脱int关键字:
getIntLimited(lowLimit, upLimit);
Run Code Online (Sandbox Code Playgroud)
另外,还要注意lowLimit和upLimit当它们传递给未初始化getIntLimited.读取未初始化的值会调用未定义的行为.
| 归档时间: |
|
| 查看次数: |
5593 次 |
| 最近记录: |