#include <iostream>#include <cctype>int main(){using namespace std;int ch;double tvarps;cout << "your tvarp: " << endl;while (cin >> ch && ch > 0 ){if(ch <= 5000 && ch >0) tvarps = 0.0;else if(ch > 5000 && ch <= 15000)tvarps = ch * 0.1; else if(ch > 15000 && ch <=35000 )tvarps = (ch - 15000)*0.15 + 1000;else if(ch > 35000)tvarps = (ch - 35000)*0.2 + 4000;cout << "tvarps: " << tvarps << endl;}return 0;}
1 回答

瀟瀟雨雨
TA貢獻1833條經(jīng)驗 獲得超4個贊
在while前加char temp[200];
把while(...)改成while(cin>>temp);
循環(huán)里第一行寫if (!isdigit(temp))break;
第二行寫ch = atoi(temp); //把字符串變成整數(shù)
以下是我做的isdigit(),僅供參考
bool isdigit(char *buf)
{
int t = 0;
if (buf[t] == '-' || buf[t] == '+')
if (buf[1] != '\0')
t ++;
for (;buf[t] != '\0'; t ++)
if (buf[t] < '0' || buf[t] > '9')
return false;
return true;
}
- 1 回答
- 0 關(guān)注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消