該程序不會運行任何人都可以幫助我理解爲什麼。這是一個硬幣翻轉游戲,應該問你想要翻轉硬幣的次數,詢問你是否打電話給頭部或尾巴,翻轉它,然後說出你猜對了還是對錯硬幣翻轉程序不會運行
# include <iostream>
# include <ctime>
# include <cstdlib>
# include <string>
using namespace std;
int tossingtimes()
{
int tosses;
cout << "How many tosses will we attempt? " << endl;
cin >> tosses;
while(tosses < 1)
{
cout << "Error tosses must be greater than or equal to 1. Please submit a correct answer." << endl;
cin >> tosses;
}
return tosses;
}
void H_T()
{
char HT;
cout << "Will you be guessing heads or tails? ('h' or 't')";
cin >> HT;
if (HT = 'h')
{
cout << "You chose to select Heads!";
}
else
{
cout << "You chose to select Tails!";
}
}
int numHT()
{
int num;
cout << "How many times will " << H_T() << "come up?";
cin >> num;
return num;
}
int head_win()
{
int heads=0;
heads++;
return heads;
}
int tails_win()
{
int tails=0;
tails++;
return tails;
}
int main()
{
srand((unsigned) time(0));rand();
int result = rand() % 2;
while (true)
{
int tosses_amount, HT, num;
tosses_amount = tossingtimes();
H_T();
num = numHT();
cin.ignore (1000, 10);
if (tosses_amount == 0)
break;
for (int i = 0; i < tosses_amount; i++)
//random number generator
{
if (result == 0)
{
int head_win();
cout << "Heads" << endl;
}
else if (result == 1)
{
int tails_win();
cout << "Tails"<<endl;
}
}
}
system ("pause");
return 0;
}
1.改進格式2。更具體(發生了什麼,你期望什麼) – BlackBear 2012-03-23 16:21:15
什麼是錯誤信息? 「不運行」不是錯誤消息。 – Marlon 2012-03-23 16:22:56
是的,請確定格式。沒有人可以幫助你,如果他們不能讀它。 – Lander 2012-03-23 16:22:58