c++/c 流处理错误的例子

#include<iostream>
#include<limits>
#include<stdio.h>
using namespace std;
int main()
{
   cout<<"*************************************************************"<<endl;
   cout<<"Enter the number corresponding to the despayired rate or action:"<<endl;
   cout<<"1) $8.7/hr                           2)$9.33/hr "<<endl;
   cout<<"$10.00/hr                           3)$11.20/hr"<<endl;
   cout<<"quit"<<endl;
   int si,hi; double monper,money,taxes,hour;
   cout<<"choose the number!"<<endl;
   cout<<"*************************************************************"'

   while(1)
   {
 cin>>si; // 输入一个数  ,例如124abc  那么 124 放入缓冲区。
 if(getchar()=='\n')  从缓冲区读剩余的内容,例子中 读出“abc”  如果是 '/n' 代表 输入的数全部 符合 整形 。
 {
        switch(si)
{
     case 1:monper=8.7;break;
     case 2:monper=9.33;break;
     case 3:monper=10.00; break;
     case 4:monper=11.20;break;
     case 5: return 0;
 default : {cout<<"error!  chose again!"<<endl;continue;}
}
cout<<"input the hour of work"<<endl;
 }
 else
 { 

     cout<<"error ,input again!"<<endl;

               cin.clear();   

              cin.ignore( numeric_limits<streamsize>::max(),'\n'); 
              continue;
 
 }
 cin>>hour;
 while(cin.rdstate()||getchar(hour)!='\n')
 {
 
 {cout<<"error ,input the  hour again!"<<endl;
     cin.clear();   
 cin.ignore( numeric_limits<streamsize>::max(),'\n'); 
 }
          cin>>hour;
 }


 // calculate:


 if(hour>40)
 hour=(hour-40)*1.5+40;
 money=hour*monper;


 if(money>=300)
 {
 taxes=300*0.15;
 if(money>=450)
 {
 taxes+=150*0.2;
 taxes+=(money-450)*0.25;
 }
 else if(money<450)
 taxes+=(money-300)*0.2;
 }
 else
 taxes=money*0.15;


 cin.clear();   
      cin.ignore( numeric_limits<streamsize>::max(),'\n'); 
 cout<<money<<"   "<<taxes<<"     "<<money-taxes<<endl;


 cout<<"choose the number"<<endl;
  }
  return 0;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值