C++ C++;获取最小程序

C++ C++;获取最小程序,c++,xcode,C++,Xcode,如果“{”在int getminimen(int numbers[],int SIZE);”之后,则不允许继续获取函数定义。我很难确定如何修复它并编译此程序。这是我目前拥有的: #include <iostream> #include <iomanip> #include <fstream> using namespace std; // Function prototypes int getSmallest(int numbers[], int SIZE)

如果“{”在int getminimen(int numbers[],int SIZE);”之后,则不允许继续获取函数定义。我很难确定如何修复它并编译此程序。这是我目前拥有的:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

// Function prototypes
int getSmallest(int numbers[], int SIZE);

int main()
{
    int count = 0;
    int numbers[SIZE];
    string inFile;

    cout << "Enter input file name:";
    cin >> inFile;
    ifstream file(inFile);

    //Reading from file
    for (count = 0; count < SIZE; count++) {
        cout << SIZE << "numbers read from file." << endl;
        cout << "The smallest value is: " << getSmallest(numbers, SIZE) << endl;
    }
}

int getSmallest(int numbers[], int SIZE)
{
    smallest = numbers[0];
    for (count = 1; count < SIZE; count++) {
        if (numbers[count] < smallest) {
            smallest = numbers[count];
        }
        return smallest;
    }
}
#包括
#包括
#包括
使用名称空间std;
//功能原型
int getminister(int数字[],int大小);
int main()
{
整数计数=0;
整数[大小];
字符串填充;
填充;
ifstream文件(infle);
//从文件中读取
用于(计数=0;计数<大小;计数++){

cout问题出在函数中。变量
最小值
计数
未定义…您未指定类型。您在main中定义了它们,但函数对main中的变量一无所知。只知道您传递的变量(数字和大小)。请这样尝试:

int getSmallest(int numbers[], int SIZE)
{
    int smallest = numbers[0];
    for (int count = 1; count < SIZE; count++) {
        if (numbers[count] < smallest) {
            smallest = numbers[count];
        }
        return smallest;
    }
}
此外,我不知道该大小是否在任何头文件中的任何位置定义,但它没有在您的程序中定义


您也没有从文件中读取。可能此链接将帮助您了解如何从文件中读取:

函数
getminimest
中的变量
minimest
count
未知。
return
语句位于
for
循环中,您忘记了最后一个
}
。整个程序中也不知道
大小。@newprogrammer101此声明中的大小是整数[SIZE]?在
main
SIZE
看起来像一个
#define
constepr
中,在
getminimest
的声明中,您将其用作一个变量。如果
SIZE
是一个
#define
,那么这将不起作用,只有当
SIZE
是一个全局
consteprxact错误行,因为在您编写的“int getminimen(int numbers[],int SIZE);”之后没有“{”,谢谢。是的,我已经定义了大小,但由于某些原因,在进行更改后,我一直得到函数定义错误@golobichYou应该显示您是如何更改程序的,以及准确的错误输出
int getSmallest(int numbers[], int SIZE)
{
    int smallest = numbers[0];
    for (int count = 1; count < SIZE; count++) {
        if (numbers[count] < smallest) {
            smallest = numbers[count];
        }
    }
    return smallest;
}