我只是C++的新手。我可以幫助我隨機化這些問題嗎?有沒有辦法隨機化這個?如何洗牌陣列問題?
我有這段代碼。有人能告訴我如何隨機化這些嗎?
string questionpart[20]={"What is the square root of 4?",
"What is the square root of 6?",
"What is the square root of 16?",
"What is the square root of 25?",
"What is the square root of 36?",
"What is the square root of 42?",
"What is the square root of 48?",
"What is the square root of 81?",
"What is the square root of 100?",
"What is the square root of 121?",
"What is the square root of 144?",
"What is the square root of 169?",
"What is the square root of 196?",
"What is the square root of 225?",
"What is the square root of 256?",
"What is the square root of 289?",
"What is the square root of 324?",
"What is the square root of 361?",
"What is the square root of 400?",
"What is the square root of 1?",
};
string partans[20]={"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"1"};
感謝提前!
創建一個索引數組(0-19)並使用rand函數對其值進行洗牌。然後回答和問題不會丟失鏈接 – nikniknik2016
您應該使用計算器並仔細檢查您的問題和答案。 – molbdnilo
您可以使用[std :: shuffle](http://www.cplusplus.com/reference/algorithm/shuffle/)。另外,你似乎在第二行中有錯誤印記。必須是「9的平方根」而不是「6的平方根」。而42和48也有同樣的問題(必須是49和64)。 – Ilya