系统("暂停")无法正常工作,谁能看到我失踪的东西?

时间:2014-04-03 22:31:51

标签: c++

我的程序有错误,不会让我编译。唯一的错误始于系统(“暂停”),但我不明白为什么我有错误,因为我做的与我一直做的程序一样。任何人都可以看到可能是什么问题?继承代码:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ 
 //Declarations
     int SIZE = 10;
     int NUMBERS[10];
     int i;
     int j;
     int temp;
 for (int i = 0; i < SIZE; i++)
 {
     cout << "Please enter a number: " << endl;
     cin >> NUMBERS[i];
 }
 for (int i = 0; i < SIZE; i++)
 {
     for (int j = 0; j < SIZE; j++)
     {
         if (NUMBERS[j] > NUMBERS[j+1])
         {
           temp = NUMBERS[j];
           NUMBERS[j] = NUMBERS[j+1];             
           NUMBERS[j+1] = temp;
         }
     }
 }
 cout << "Sorted List" << endl;
 cout << "===========" << endl;
 for (int i = 0; i < SIZE; i++)
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;
 }

   system("pause");
   return 0;
 }

1 个答案:

答案 0 :(得分:2)

 for (int i = 0; i < SIZE; i++) {
                             // ^^^ add this missing bracket
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;
 }
^^^  // closing bracket, but has no opening match

当然你可以在这种情况下跳过大括号(因为正文中只有一行)所以这也是解决方案:

 for (int i = 0; i < SIZE; i++)
     cout << "Number " << i + 1 << ": " << NUMBERS[i] << endl;
相关问题