---
# System prepended metadata

title: 簡易計算機
tags: [實習題目]

---

###### tags: `實習題目`
# 簡易計算機
## Description
請設計一簡易計算機，計算機功能有`+` `-` `*` `/` `^(平方)`  `√(根號用#表示)`，一開始先輸入一個數字，接下來輸入指令直到讀取`=`結束計算。

**請使用函式並取到小數點第三位 ( 3ω3)**

## Sample Input & Output
![](https://i.imgur.com/079IJKM.png)

<!--解答(by hsu17)
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
void calculater(char ch,float& num,float n)
{
   // cout<<& num;
    switch(ch)
    {
    case '+':
        num+=n;
        break;
    case '-':
        num-=n;
        break;
    case '*':
        num*=n;
        break;
    case '/':
        num=num/n;
        break;
    case '^':
        num=pow(num,n);
        break;
    case '#':
        num=sqrt(num);
        break;

    }
    //cout<<"num ="<<num<<endl;
}

int main()
{
    float num,n;
    //cout<<& num;
    char cha='+';
    cout<<"please input the number\n";
    cin>>num;
    while(1)
    {
        // cout<<"please input the character(+ - * /)\n";
        cin>>cha;
        if(cha=='=')break;
        if(cha=='#')
        { calculater(cha,num,n);
        continue;
        }
        cin>>n;
        calculater(cha,num,n);

    }
    cout<<"result is "<<fixed<<setprecision(3)<<num<<endl;



} --!>

