int main(){
srand(time(0));
int numOfTimes;
int randNum;
int oneRoll = 0, twoRoll = 0, threeRoll = 0, fourRoll = 0, fiveRoll = 0, sixRoll = 0;
int onePercent, twoPercent, threePercent, fourPercent, fivePercent, sixPercent;
int count = 0;
cout << "How many times would you like to roll the dice?\n";
cin >> numOfTimes;
while (numOfTimes <= 0){
cout << "Invalid entry enter a number greater than 0\n";
cout << "How many times would you like to roll the dice?\n";
cin >> numOfTimes;
}
while (count < numOfTimes)
{
randNum = rand() % 6 + 1;
switch (randNum)
{
case 1:
oneRoll++;
break;
case 2:
twoRoll++;
break;
case 3:
threeRoll++;
break;
case 4:
fourRoll++;
break;
case 5:
fiveRoll++;
break;
case 6:
sixRoll++;
break;
default:
cout << "\n";
}
count++;
}
onePercent = (int)((oneRoll*100.0) /numOfTimes);
twoPercent = (int)((twoRoll*100.0)/numOfTimes);
cout << " # Rolled # Times % Times" << endl;
cout << "--------- -------- --------" << endl;
cout << "1 " << oneRoll << " " <<double (onePercent) << endl;
cout << "2 " << twoRoll << " " << "" << endl;
cout << "3 " << threeRoll << " " << ""<< endl;
cout << "4 " << fourRoll << " " <<"" << endl;
cout << "5 " << fiveRoll << " " <<"" << endl;
cout << "6 " << sixRoll << " " <<"" << endl;
1パーセントをダブルとして出力する必要があります。だから私はint型としてdouble型に変換したので、このような2つのゼロ(14.00)しか表示されませんが、唯一の変換では変換されません14C++は動作しないdouble型にキャストしよう
doubleに変換するための正しい構文ではありませんか? – merlin2011
[mcve]を含めてください。あなたは、単純な変換問題のために、たくさんのコードを歩き回ることは実際には期待できません。 –
ダブルスを印刷したい場合は、変数を倍にします。 – tinstaafl