我想寫一個C++程序,輸入1到100之間的五個數字,然後程序輸出每個數字出現多少次。這是迄今爲止我所擁有的,但我一直在收到未解決的錯誤消息。C++程序計數出現的數字
#include <iostream>
using namespace std;
void fillArray(int a[], int& size, int& numberUsed)
{
int i, hist[1000];
cout << "Enter 5 integers between 1 and 100" << endl;
for (i=0; i<size; i++)
{
cin >> a[i];
if(a[i] > 100)
{
i--;
cout << "Num too big! 100 is max!" << endl;
}
}
numberUsed = i;
for (i=0; i<1000; i++)
hist[i] = 0;
for (i=0; i<numberUsed; i++)
{
hist[a[i]]++;
}
for (i=0; i<1000; i++)
if(hist[i])
cout << i << " occurs " << hist[i] << " times!" << endl;
}
該錯誤消息說,下面的「錯誤LNK2019:解析外部符號主函數引用_ _tmainCRTStartup」
錯誤信息很清楚 - 你沒有main()函數。 –
好的,謝謝,我是新來的,所以還在學習。我可以把整個代碼放在主函數中嗎? – mathlete
你可能要編寫一個'main()'函數來完成可能需要的初始化操作,然後調用你的'fillArray()'函數。 –