#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int SIZE = 10;
int NUMBERS[SIZE];
int i;
int j;
int temp;
for((i = 0) to (SIZE - 2))
{
for((j = 0) to (SIZE - 2))
{
if(NUMBERS[j] < NUMBERS[j + 1])
{
temp = NUMBERS[j]
NUMBERS[j] = NUMBERS[j+1]
NUMBERS[j+1] = temp
}
}
}
cout << "Sorted list";
cout << "===========";
for((i = 0) to (SIZE - 1))
{
cout << "Number ", i + 1, ": ", NUMBERS[i]
}
system("PAUSE");
return EXIT_SUCCESS;
}
我一直在:
第18行&amp; 34:预期
;' before "to" line 32: expected
)'之前';'令牌
我无法弄清楚原因。 非常感谢任何帮助!
答案 0 :(得分:0)
您错过了代码中的一些;
(以及其他一些代码)。试试这个版本:
using namespace std;
int main(int argc, char *argv[])
{
int SIZE = 10;
int NUMBERS[SIZE];
int temp;
for(int i = 0; i< SIZE - 2; i++)
{
for(int j = 0; j < SIZE - 2; j++)
{
if(NUMBERS[j] < NUMBERS[j + 1])
{
temp = NUMBERS[j];
NUMBERS[j] = NUMBERS[j+1];
NUMBERS[j+1] = temp;
}
}
}
cout << "Sorted list";
cout << "===========";
for(int i = 0; i < SIZE - 1; i++)
{
cout << "Number ", i + 1, ": ", NUMBERS[i];
}
system("PAUSE");
return EXIT_SUCCESS;
}
请考虑您应该初始化NUMBERS
。
答案 1 :(得分:-1)
尝试:
for(i = 0; i <= (SIZE - 2); i++)
{
for(j = 0; j<=(SIZE - 2); j++)
{
if(NUMBERS[j] < NUMBERS[j + 1])
{
temp = NUMBERS[j];
NUMBERS[j] = NUMBERS[j+1];
NUMBERS[j+1] = temp;
}
}
}
cout << "Sorted list";
cout << "===========";
for(int i = 0; i <= SIZE - 1; i++)
{
cout << "Number ", (i + 1), ": ", NUMBERS[i];
}
system("PAUSE");
return EXIT_SUCCESS;