![](/img/trans.png)
[英]Cin appears to be failing inside this loop. Can anyone explain what I'm doing wrong?
[英]system(“pause”) not working, can anyone see what I'm missing?
我的程序有错误,不会让我编译。 唯一的错误始于system(“ pause),但是我不明白为什么会有错误,因为我做错误的方式与我经常做程序一样。任何人都可以看到问题所在吗?以下代码:
#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;
}
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.