我有一个for循环的函数,如下所示:输出2个值中的一个线路输入For循环 - Visual C
int fnSearch(int arnSalaries [10][2], int nSalary, char cFound)
{
int nRow, nCol;
printf("Please enter the Salary to find the Employee ID : ");
scanf("%d", &nSalary);
for(nRow = 0; nRow < 10; nRow++)
{
if(nSalary == arnSalaries[nRow][1])
{
printf("\%d found - Employee ID matching that salary is: %d\n",
nSalary, arnSalaries[nRow][0]);
cFound = 'Y';
//nRow = 10; /* This is to break out of the loop */
}
}
if(cFound == 'N')
{
printf("Sorry, that salary does not match an employee\n");
}
return cFound;
}
当我在薪金诸如键入“10000”时,输出如下:
10000 found - Employee ID matching that salary is: 21
10000 found - Employee ID matching that salary is: 23
如何更改代码,以便它会显示类似以下内容:
10000 found - Employee ID(s) matching that salary is/are: 21, 23
编辑: 我不寻找任何代码要写 - 只是在正确的方向提示我应该看什么来解决这个问题
有几种方法。你有没有试图自己解决这个问题?这就是SO的首选,如果你碰到一堵砖墙,还会留下一个问题。 –
将循环中另一个数组中的匹配结果保存起来,然后在循环结束后将这些值输出。 – OldProgrammer
感谢您的评论 - 即时通讯新的C - 最近才开始,所以我不会很高级这种事情! –