未初始化的错误

Ral*_*one 0 c++

我需要做些什么来修复程序中未初始化的错误?该程序假设打印一个数字具有的除数,但仍然显示错误,表示变量c未初始化.

/*
/ Name: Ralph Lee Stone
/ Date: 10/10/2013
/ Project: RLStone3_HW_08
/ Description: This program gets a positive value and determines the number of divisors    it has.
*/
#include <iostream>
using namespace std;

int DivisorCount(int x)
{
  int counter = 0;
  for(int c; x < c; c++)
  {
    if (x%c==0)
     counter++;
  }
  return counter;
}
int main()
{
  int x;
  cout << "Please a positive value: ";
  cin >> x;
  cout << x << "has this many divsors: " << DivisorCount(x);
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*rey 5

您需要使用一些值初始化它:

for(int c = 1; x < c; c++)
//        ^^^ here
Run Code Online (Sandbox Code Playgroud)

还有,你的意思是写c < x而不是x < c

  • @Ralphs17这看起来像另一个问题.你可以再详细一点吗?发布确切的错误消息. (2认同)