我是 C++ 新手,并试图制作两个简单的函数,但出了点问题。
我正在尝试执行以下操作:
1.Function for input some data.
2.Function to show what data is input.
我只是想让它变得简单。到目前为止我写的代码是:
#include <iostream>
void masiv()
{
int x[10];
int n, i;
int min;
int max=0, imax=0, imin;
cout << "Enter the number of elements: ";
cin >> n;
for(i=0; i < n; i++)
{
cout << "Input value for x["<<i<<"]=";
cin >> x[i];
if (min > x[i])
{
min = x [i];
imin = i;
}
if (max < x[i])
{
max = x[i];
imax = i;
}
}
void rezult()
{
cout << "the smallest value on is xthe biggest value on is x["<<imin<<"]=" << min <<endl;
cout << "nai golqmata stoinost e na x["<<imax<<"]=" << max <<endl;
}
void main()
{
masiv();
rezult();
}
我有一堆错误。我知道这是糟糕的代码,但正如我所提到的,我才刚刚开始。谢谢
Ps对不起我的英语
编辑:使用此代码。
#include <iostream>
using namespace std;
void masiv(int& min, int&max)
{
int x[10];
int n;
int i;
int imin, imax;
cout << "Enter the number of elements: ";
cin >> n;
for(i=0; i < n; i++)
{
cout << "Input value for x["<<i<<"]=";
cin >> x[i];
if(min > x[i])
{
min = x [i];
imin = i;
}
if(max < x[i])
{
max = x[i];
imax = i;
}
}
}
void rezult(int min, int max)
{
cout << "the smallest value on is x= " << min << endl;
cout << "the biggest value on is x= " << max << endl;
system ("pause");
}
int main(int argc, char** argv)
{
int min = 999999;
int max = -999999;
masiv(min,max);
rezult(min,max);
return 0;
}