我正在嘗試完成作業,並且無法在任何地方找到它。我試圖將輸入數字與隨機生成的數字進行匹配,並顯示5個數字中有多少是正確的(還有輸贏信息)。這是我迄今爲止的任何幫助,將不勝感激。匹配號碼
#include <iostream>
#include <cstdlib>
using namespace std;
void main()
{
//variables
int lottery[5], user[5];
int count = 0;
int num1, num2, num3, num4, num5;
int winnum;
//generating numbers
for (int i=0; i <5; i++)
{
lottery[i] =1+rand()%9;
}
//input
cout << "Enter a digit between 0-9: ";
cin >> num1;
// ...
cin >> num5;
winnum = rand();
//display
cout << "Winning Lottery Numbers: " << winnum << endl;
cout << "Your ticket Numbers: "
<< num1 << num2 << num3 << num4 << num5 << endl;
//matching the numbers
//HELP!
system("pause");
}
在main的開頭調用'srand(time(NULL))'來獲得每次執行時不同的彩票號碼。你遇到的具體問題是良好的信息。 – chris 2012-04-20 01:27:00
添加了「作業」標籤。 – Aaron 2012-04-20 01:28:27
還是不太確定該怎麼做,對不起,我是一個非常大的新手。我試圖找出如何創建一個輸出,說明有多少用戶輸入的數字與隨機生成的數字匹配。 – user1345398 2012-04-20 01:41:42