一个简单的C++ while 循环问题
//初学C++麻烦哪位大神教导一下,我想得到的效果是可以循环的输入工作时间和工作时薪直到工//作时间输入等于0时才跳出循环结束//用的是VS2010C++谢谢了#incl...
//初学C++ 麻烦哪位大神教导一下,我想得到的效果是 可以循环的输入 工作时间 和工作时薪 直到工
//作时间输入等于0时才跳出循环 结束
//用的是VS 2010 C++ 谢谢了
#include<iostream>
using namespace std;
int main()
{
int worktime,wage_per_hour,wage;
cin>>worktime;
while (worktime != 0)
{
cout<<"Please input employee’s work time and wage_per_hour:"<<endl;
cin>> worktime >> wage_per_hour;
if(worktime<=40)
{
wage = wage_per_hour * worktime;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
else
if(worktime>40,worktime<=50) //当 工作时间在40-50之间时 执行下列语句
{
wage = wage_per_hour * 40 + (worktime-40) * wage_per_hour * 1.5;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
else
wage = wage_per_hour * 40 + wage_per_hour * 10 ;
wage = wage + wage_per_hour * (worktime - 50) * 3;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
} 展开
//作时间输入等于0时才跳出循环 结束
//用的是VS 2010 C++ 谢谢了
#include<iostream>
using namespace std;
int main()
{
int worktime,wage_per_hour,wage;
cin>>worktime;
while (worktime != 0)
{
cout<<"Please input employee’s work time and wage_per_hour:"<<endl;
cin>> worktime >> wage_per_hour;
if(worktime<=40)
{
wage = wage_per_hour * worktime;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
else
if(worktime>40,worktime<=50) //当 工作时间在40-50之间时 执行下列语句
{
wage = wage_per_hour * 40 + (worktime-40) * wage_per_hour * 1.5;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
else
wage = wage_per_hour * 40 + wage_per_hour * 10 ;
wage = wage + wage_per_hour * (worktime - 50) * 3;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
return 0;
}
} 展开
展开全部
#include<iostream>
using namespace std;
int main()
{
int worktime,wage_per_hour,wage;
//cin>>worktime;
do
{
cout<<"Please input employee's work time and wage_per_hour:"<<endl;
cin>> worktime >> wage_per_hour;
if(worktime<=40)
{
wage = wage_per_hour * worktime;
cout<<"The employee's wage :"<<wage<<endl;
}
else
if(worktime>40 && worktime<=50) //当 工作时间在40-50之间时 执行下列语句
{
wage = wage_per_hour * 40 + (worktime-40) * wage_per_hour * 1.5;
cout<<"The employee's wage :"<<wage<<endl;
}
else
{
wage = wage_per_hour * 40 + wage_per_hour * 10 ;
wage = wage + wage_per_hour * (worktime - 50) * 3;
cout<<"The employee's wage :"<<wage<<endl;
}
// cin>>worktime;
}while (worktime != 0);
system("pause");
return 0;
}
你的循环里度直接return 0了,不可能执行多次。
另外 if(worktime>40,worktime<=50) //当 工作时间在40-50之间时 执行下列语句
这行应该是 : if(worktime>40 && worktime<=50) //当 工作时间在40-50之间时 执行下列语句
2015-11-09
展开全部
#include<iostream>
using namespace std;
int main()
{
int worktime,wage_per_hour,wage;
while (1)
{
cout<<"Please input employee’s work time and wage_per_hour:"<<endl;
cin>>worktime;
if(worktime==0)
{
exit(worktime);
}
cin>>wage_per_hour;
if(worktime<=40)
{
wage = wage_per_hour * worktime;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
else
if(worktime>40,worktime<=50) //当 工作时间在40-50之间时 执行下列语句
{
wage = wage_per_hour * 40 + (worktime-40) * wage_per_hour * 1.5;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
else
{
wage = wage_per_hour * 40 + wage_per_hour * 10 ;
wage = wage + wage_per_hour * (worktime - 50) * 3;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
}
return 0;
}
using namespace std;
int main()
{
int worktime,wage_per_hour,wage;
while (1)
{
cout<<"Please input employee’s work time and wage_per_hour:"<<endl;
cin>>worktime;
if(worktime==0)
{
exit(worktime);
}
cin>>wage_per_hour;
if(worktime<=40)
{
wage = wage_per_hour * worktime;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
else
if(worktime>40,worktime<=50) //当 工作时间在40-50之间时 执行下列语句
{
wage = wage_per_hour * 40 + (worktime-40) * wage_per_hour * 1.5;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
else
{
wage = wage_per_hour * 40 + wage_per_hour * 10 ;
wage = wage + wage_per_hour * (worktime - 50) * 3;
cout<<"The employee’s wage :"<<wage<<endl;
system("pause");
}
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询