C 如何将用户输入与数组进行比较,检查其是否小于上次输入

C 如何将用户输入与数组进行比较,检查其是否小于上次输入,c,arrays,input,compare,C,Arrays,Input,Compare,我必须请求用户输入10个不同的数字。我必须查看用户输入是否小于最后输入的数字(添加到数组中)。我很难比较它,因为我的逻辑似乎合理,但无论出于什么原因,它都不会在循环中保持较低的输入数。也许你们可以看看我的if声明中的问题所在。getNum()函数只获取用户输入,并在用户感兴趣时返回它。提前谢谢 #include <stdio.h> //including for the use of printf /* == FUNCTION PROTOTYPES == */ int getN

我必须请求用户输入10个不同的数字。我必须查看用户输入是否小于最后输入的数字(添加到数组中)。我很难比较它,因为我的逻辑似乎合理,但无论出于什么原因,它都不会在循环中保持较低的输入数。也许你们可以看看我的if声明中的问题所在。getNum()函数只获取用户输入,并在用户感兴趣时返回它。提前谢谢

#include <stdio.h>   //including for the use of printf

/* == FUNCTION PROTOTYPES == */
int getNum(void);

/* === COMPILER DIRECTIVE - to ignore the sscanf() warning === */
#pragma warning(disable: 4996)


int main(void)
{   
// defining varibles
int myArray[11] = { 0 };
int counter = 0;
int indexTracker = -1;
int numInput = 0;
int lowestNum = 0;
int lowestNumPlace = 0;

// printing as to why I need 10 numbers
printf("I require a list of 10 numbers to save the world!\n");

// while loop
// while 'counter' is less than or equal to 9, loop
while (counter <= 9)
{
    // adding 1 to each varible, everytime the program loops
    indexTracker += 1;
    counter += 1;

    // printing to request a number, giving which number they are 
            // inputting
    // out of the list of 10
    // calling getNum() for input, saving the number into the array
    printf("Please enter a number for #%d: ", counter, "spot\n");
    numInput = getNum();
    myArray[indexTracker] = numInput;

    if (numInput <= myArray[indexTracker])
    {
        lowestNum = numInput;
        lowestNumPlace = indexTracker;
    }
}
// printing the lowest value and its index
printf("The lowest number is: %d at index [%d].", lowestNum, 
lowestNumPlace);

return 0;
}
#包括//包括用于printf
/*==函数原型==*/
int getNum(void);
/*==编译器指令-忽略sscanf()警告===*/
#杂注警告(禁用:4996)
内部主(空)
{   
//定义变量
int myArray[11]={0};
int计数器=0;
int indexTracker=-1;
int numInput=0;
int lowestNum=0;
int lowersnumplace=0;
//为什么我需要10个数字
printf(“我需要一个包含10个数字的列表来拯救世界!\n”);
//while循环
//当“计数器”小于或等于9时,循环

而(计数器您总是将一个新值分配给
lowestNum

numInput = getNum();
myArray[indexTracker] = numInput;

if (numInput <= myArray[indexTracker])
{
    lowestNum = numInput;
    lowestNumPlace = indexTracker;
}
numInput=getNum();
myArray[indexTracker]=numInput;

如果(numInput您总是将一个新值赋给
lowerstnum

numInput = getNum();
myArray[indexTracker] = numInput;

if (numInput <= myArray[indexTracker])
{
    lowestNum = numInput;
    lowestNumPlace = indexTracker;
}
numInput=getNum();
myArray[indexTracker]=numInput;

如果(numInput啊好多了!谢谢!还必须包括用户的第一次输入总是初始的最小值。数组:染料有点混乱和不知所措,你的初始化
lowstnum=0;
会使该值很难更改。在这种情况下,你可以使用INT\u MAX这样的宏。啊uch更好!谢谢!还必须包括用户的第一个输入始终是初始的lowestNum值。数组:染料有点混乱和不知所措,初始化
lowestNum=0;
会使该值很难更改。在这种情况下,可以使用INT_MAX之类的宏。