【发布时间】:2022-07-06 02:11:15
【问题描述】:
我的倒数第二行中的bin 会显示类似于3282692812 的内容,而这意味着它应该有所不同。其他一切都很好,我已经尝试在网上搜索,但我找不到任何相关信息。
string a;
int amount;
cout << "1-10k 2-2k 3-1k: ";
cin >> a;
cout << "\n";
cout << "How many numbers do you want to be generated?: ";
cin >> amount;
cout << "\n";
long bin = 0;
if (int(a) = 1)
{
bin = 60457811425;
}
else if (a == 2)
{
bin = 60457811474;
}
else if (a == 3)
{
bin = 6045781165;
}
for (int i = 0; i < amount; i++)
{
cout << bin << rand() % 10 << rand() % 10 << rand() % 10 << rand() % 10 << rand() % 10 << rand() % 10 << "|" << setw(2) << setfill('0') << rand() % (13 - 1) + 1 << "|" << rand() % (2031 - 2022) + 2022 << "|" << setw(3) << setfill('0') << rand() % 999 << "\n";
}
system("pause");
【问题讨论】:
-
如果显示的
bin值不正确,您可以删除所有对rand()的调用,因为它们只是分散注意力。此外,不需要多次显示它。 -
请澄清您所说的“当它意味着不同时”是什么意思。您期望该程序的输出是什么?