簡體   English   中英

無法找出要為函數的最后一個代碼字符串寫什么

[英]cant figure out what to write for the last string of code for function

嗨,大家好,這是我到目前為止對函數的了解,問題是讓我編寫一個函數findpattern() ,該函數將接收表示三個保齡球得分的三個整數。 該功能將確定隨后的分數的模式,並打印以下六種情況之一 (請確保您有這六種情況):

  stayed the same –- all three scores were the same 

  increasing –- the scores are going steadily upward

  decreasing –- the scores are going steadily downward

  up and down –- the scores first went up, then went down

  down and up –- the scores first went down, then went up

  two the same –- two consecutive scores were the same, and the
 other one (first or third) was either higher or lower     

這是到目前為止我無法弄清楚的最后一部分,對您的幫助將不勝感激

void findpattern(int score1, int score2, int score3)
{
   if (score1 == score2 && score1 == score3 && score2 == score3 )
   {
      cout << "all three scores were the same" << endl;
   } else if (score1 < score2 && score2 < score3) {
      cout << "the scores are going steadily upward" << endl;
   } else if (score1 > score2 && score2 > score3) {
      cout<<"the scores are going steadily downward"<<endl;
   } else if(score1 < score2 && score2 > score3) {
      cout << "the scores first went up, then went down" << endl;
   } else if (score1 > score2 && score2 < score3) {
      cout<<"the scores first went down, then went up"<<endl;
   }
else if ( ( ( score1 == score2 ) && score2 != score3 ) || ( ( score2 == score3 ) && ( score2 != score1 ) ) )
    cout << "two scores are equal" << endl;

您可以嘗試以下方法:

else if((score1==score2 || score2==score3) && ( (score1 > score3) || (score1 < score3)))
    cout<<"two the same";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM