帮助[错误]预期在'{'令牌之前的不合格ID [英] HELP [error] expected unqualified-id before '{' token

查看:344
本文介绍了帮助[错误]预期在'{'令牌之前的不合格ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
using namespace std;
int minimum (double grades [], int N)
{
	double ans = 101;
	for ( int i = 0; i< N; i++)
		if (grades [i] < ans)
		ans = grades [i];
		return ans;
}

int maximum (double grades [], int N)
{
	double ans = -1;
	for (int i=0 ; i<N ; i++)
	if (grades [i] > ans)
	ans = grades [i];
	return ans;
}

{
double min_value;
int min_index;
double temp;
for (int i =0; i<npts -1 ; i++)
{
min_value = x[i];
min_index = i;
for (int j=i+1; j<npts; j++)
{
	if (x[j] < min_value)
	{
		min_value = x[j];
		min_index = j;
	}
}
temp = x[min_index];
x[min_index]= x[i];
x[i] = temp;
}
	return;
}


int main ()
{
	int N;
	double grades [100];
	cout << "Enter the number of students" << endl;
	cin >> N;
	int i = 0;
	double value;
	while (i<N)
	{
		com >> value;
		if (value >= 0 && value <=100)
		{
			grades [i] = value;
			i++;
		}
		else
		{
			cout << "Invalid grade. ReEnter" <<endl;
		}
	}
	cout <<"Maximum grade is = "<< maximum (grades,N) <<endl;
	cout << "Minimum grade is= " << minimum (grades,N) <<endl;
	cout << "Avergage grade is= "<< average (grades,N) <<endl;
	cout << "Numbers of the students above average are = " << nAboveAvg (grades,N) <<endl;
	sort (grades,N);
	cout << "Grades after sorting"<< endl;
	for (int i=0; i<n; i++)
	cout << grades[i] << " ";
	cout<< endl;
	system ("pause");
}



我尝试过的事情:

当我编译它时,它显示了



What I have tried:

When I compile this, it shows me

[error] expected unqualified-id before ''{'' token


在第26行,我像这样>>突出显示了<<.请帮助我


at line 26 where I highlighted like this >> <<. Please help me

int maximum (double grades [], int N)
{
	double ans = -1;
	for (int i=0 ; i<N ; i++)
	if (grades [i] > ans)
	ans = grades [i];
	return ans;
}

>> { <<
double min_value;
int min_index;
double temp;
for (int i =0; i<npts -1 ; i++)

推荐答案

问题出在哪里很明显.您已在>>中将其突出显示.和<<.只需删除{字符.就这样!

另外,如果您想保持代码的可读性和可维护性,请不要这样做:
It''s quite obvious where the problem is. You highlighted it in >> and <<. Just delete the { character. That''s it!

Also, if you want to keep your code readable and maintainable, do not ever do this:
int maximum (double grades [], int N)
{
    double ans = -1;
    for (int i=0 ; i<N ; i++)
    if (grades [i] > ans)
    ans = grades [i];
    return ans;
}


改为执行此操作.花括号可以使代码可读,可调试,并且对于哪一行属于哪个块不遗余力.另外,正确缩进代码.


Do this instead. The curly braces are there to make the code readable, debuggable, and leave no double as to which lines belong in which block. Also, indent your code properly.

int maximum (double grades [], int N)
{
    double ans = -1;

    for (int i=0 ; i<N ; i++)
    {
        if (grades[i] > ans)
        {
            ans = grades [i];
        }
    }

    return ans;
}


Dave的技巧是最佳实践:使用缩进和花括号表示清晰的代码和可维护的代码.

但是您的错误是新功能应该从那里开始,但是头部被删除了.我的猜测是它是一种排序功能.
The tips of Dave are best practice: use indentation and braces for clear code and maintainable code.

But your error is that a new function should start there, but the head got deleted. My guess is that it is a sorting function.
void sort(double x[], int npts)// <= this or similar is missing
{
double min_value;
int min_index;
double temp;
for (int i =0; i<npts -1 ; i++)
{
min_value = x[i];
min_index = i;
for (int j=i+1; j<npts; j++)
{
	if (x[j] < min_value)
	{
		min_value = x[j];
		min_index = j;
	}
}
temp = x[min_index];
x[min_index]= x[i];
x[i] = temp;
}
	return;
}


这篇关于帮助[错误]预期在'{'令牌之前的不合格ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆