Jinto
Jinto

Reputation: 179

Too few arguments in function

I'm writing a function getIntLimited that can only except a number between a certain maximum and minimum value. There is no assigned max or min at the moment, but the code should essentially function nonetheless. However, I seem to be getting an error that says I have too few arguments in the function, but I am unsure as to why that is. Here's my code:

#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;

}                             

Upvotes: 0

Views: 8412

Answers (2)

kaushal kishore
kaushal kishore

Reputation: 11

getIntLimited(int lowLimit, int upLimit); instead of this use getIntLimited(lowLimit, upLimit); as datatype is not required during function call

Upvotes: 1

dbush
dbush

Reputation: 223872

In your main function, this is not a function call:

getIntLimited(int lowLimit, int upLimit);

Get rid of the int keywords:

getIntLimited(lowLimit, upLimit);

Also, note that lowLimit and upLimit are not initialized when they are passed to getIntLimited. Reading uninitialized values invokes undefined behavior.

Upvotes: 6

Related Questions