查看完整版本: 有點急~~~關於 這兩題 其中1題 是 do while
頁: [1]

asdfg0205 發表於 2016-11-7 02:23 PM

有點急~~~關於 這兩題 其中1題 是 do while

本帖最後由 asdfg0205 於 2016-11-7 02:24 PM 編輯

這是 老師 給我們 期中考  建議要會的題目 有12題 我能寫出10題了 可是這兩題 我腦袋有點打結....
目前 交了 if   for   do while 這些簡單的  還沒有 交遞迴和陣列之類的 所以不能有 陣列.遞迴出現~~~

第六題 我用 for 寫出來了 讓他輸入 多個正整數 當輸入負數就停止 (我只會寫到這...)
因為 接下來要判斷 因為 我不知道 if(這裡面 該怎麼去寫) 頭腦有點打結.....

第七題 我就真的 GG了  這題是要用 do while (我只知道 do的敘述裡面 不管有沒有達成都會跑一次)
do裡面的敘述因該是放 詢問成績對吧  
但是 while() 之後我就不知道該怎麼打了...

老師有教  可是 do while 我聽不太懂  但是 for我聽得懂 只是 第六題 if 有點讓我頭腦打結....
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div><div></div>

Josie_2016 發表於 2016-11-7 05:13 PM

第六題(若3的倍數為累減請乘-1)int count1 = 0,count2=0,count3=0;
int sum1 = 0, sum2 = 0, sum3 = 0;
int intInput = 1;
while (intInput>0)
{
        string input = Console.ReadLine();
         if (int.TryParse(input, out intInput) && intInput>0)
         {
                  if (intInput % 3 == 0 && intInput % 5 == 0)//3及5的倍數
                    {
                        count3++;
                        sum3 += intInput;
                    }
                    else if (intInput % 5 == 0)//5的倍數
                    {
                        count2++;
                        sum2 += intInput;
                    }
                    else if (intInput % 3 == 0)//3的倍數
                    {
                        count1++;
                        sum1 += intInput;
                    }
                }
            }
            Console.WriteLine("3的倍數個數{0},累加值{1}",count1,sum1);
            Console.WriteLine("5的倍數個數{0},累加值{1}", count2, sum2);
            Console.WriteLine("3及5的倍數個數{0},累加值{1}", count3, sum3);第七題int chinese = 0, english = 0;
            int count1 = 0,count2=0;
            int both = 0;
            int avg = 0;
            int i = 1;
            do
            {
                int j=1;
                do{
                    Console.WriteLine("請輸入第{0}位學生{1}成績:", i, (j == 2) ? "英文" : "國文");
                    string input = Console.ReadLine();
                    int temp = 0;
                    if (int.TryParse(input, out temp))
                    {
                        if (j == 1)
                        {
                            chinese = temp;
                        }
                        else
                        {
                            english = temp;
                        }
                    }
                    j++;
                    
                }while(j<=2);
                if (chinese < 60 && english < 60) both++;
                if (chinese < 60) count1++;
                if (english < 60) count2++;
                if ((chinese + english) / 2 < 60) avg++;
                    i++;
            } while (i <= 4);
            Console.WriteLine("國文不及格人數{0}人" , count1);
            Console.WriteLine("英文不及格人數{0}人" , count2);
            Console.WriteLine("兩科皆不及格人數{0}人" , both);
            Console.WriteLine("平均不及格人數{0}人" , avg);...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div>
頁: [1]