---
# System prepended metadata

title: 浤昕作業

---

#    浤昕作業
##    第一題
0到100猜數字，輸入999退出，猜中顯示猜測次數



```cpp=
#include <iostream>
#include <cstdlib> 
#include <ctime> 
using namespace std;

int main(){
    int min = 0;//亂數最小值
    int max = 100;//亂數最大值
    srand(5);
    int target = rand() % (max - min + 1)+min;
    int input = 0;//input為使用者輸入之數字
    int times=1; //times為猜測次數
    /*debug : cout<<target;*/
    while (true) {
        cout<<"請輸入1到100之間的數字:"<<endl;
        cin>>input;
        if (input == 999){
            break;
        }
        else if (input == target){
            cout << "你猜中了，共用了"<<times<<"次"<<endl;
            break;
        }
        else{
            cout << "你沒猜中，在試一次"<<endl;
            times += 1;
        }
    }
    return 0;
}

```

---

##    第二題
### 簡易解法(無防呆防溢位)
```cpp=    
#include <iostream>
using namespace std;

int main(){
    float height, width, result;
    cout<<"please insert height :"<<endl;
    cin>>height;
    cout<<"please insert width :"<<endl;
    cin>>width;
    result = height * width;
    cout<<"the surface area is"<<result<<endl;
    
    return 0;
}

```
