c语言程序设计试题
编写一个程序,提示用户从键盘输入一个星期的薪水(以美元为单位)和工作时数,它们均为浮点数,然后计算并输出每个小时的平均薪水,输入格式如下:Youraveragehourl...
编写一个程序,提示用户从键盘输入一个星期的薪水(以美元为单位)和工作时数,它们均为浮点数,然后计算并输出每个小时的平均薪水,输入格式如下:Your average hourly pay rate is 7 dollars and 54 cents.
展开
3个回答
展开全部
#include<iostream>
using namespace std;
int main()
{
double weekprice,dol,cent,time;
cout<<"请输入一周薪水"<<endl;
cin>>weekprice;
fflush(stdin);
cout<<"请输入工作时间"<<endl;
cin>>time;
if(weekprice/time==0)
{
cent=(int)(weekprice*10.0/time);
cout<<"Your average hourly pay rate is 0 dollars and"<<cent<<" cents."<<endl;
return 0;
}
else
{
dol=(int)(weekprice/time);
cent=(int)((weekprice-dol*time)*10.0/time);
cout<<"Your average hourly pay rate is "<<dol<<" dollars and "<<cent<<" cents."<<endl;
return 0;
}
}
using namespace std;
int main()
{
double weekprice,dol,cent,time;
cout<<"请输入一周薪水"<<endl;
cin>>weekprice;
fflush(stdin);
cout<<"请输入工作时间"<<endl;
cin>>time;
if(weekprice/time==0)
{
cent=(int)(weekprice*10.0/time);
cout<<"Your average hourly pay rate is 0 dollars and"<<cent<<" cents."<<endl;
return 0;
}
else
{
dol=(int)(weekprice/time);
cent=(int)((weekprice-dol*time)*10.0/time);
cout<<"Your average hourly pay rate is "<<dol<<" dollars and "<<cent<<" cents."<<endl;
return 0;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
int main()
{
double weekSalary,workingTime;
int dol,cent;
do
{
cout<<"请输入一周薪水,输入须为数值且不小于零,单位为“美元”)"<<endl;
cin>>weekSalary;
}while(weekSalary<0)
do
{
cout<<"请输入工作时间,输入须为数值且大于0.0小于168.0,单位为“小时”)"<<endl;
cin>>workingTime;
}while(workingTime<=0)
if(weekprice/workingTime==0)
{
cent=(int)(weekSalary*10.0/workingTime);
cout<<"Your average hourly pay rate is 0 dollars and"<<cent<<" cents."<<endl;
}
else
{
dol=(int)(weekSalary/workingTime);
cent=(int)((weekSalary-dol*workingTime)*10.0/wokingTime);
cout<<"Your average hourly pay rate is "<<dol<<" dollars and "<<cent<<" cents."<<endl;
}
return 0;
}
using namespace std;
int main()
{
double weekSalary,workingTime;
int dol,cent;
do
{
cout<<"请输入一周薪水,输入须为数值且不小于零,单位为“美元”)"<<endl;
cin>>weekSalary;
}while(weekSalary<0)
do
{
cout<<"请输入工作时间,输入须为数值且大于0.0小于168.0,单位为“小时”)"<<endl;
cin>>workingTime;
}while(workingTime<=0)
if(weekprice/workingTime==0)
{
cent=(int)(weekSalary*10.0/workingTime);
cout<<"Your average hourly pay rate is 0 dollars and"<<cent<<" cents."<<endl;
}
else
{
dol=(int)(weekSalary/workingTime);
cent=(int)((weekSalary-dol*workingTime)*10.0/wokingTime);
cout<<"Your average hourly pay rate is "<<dol<<" dollars and "<<cent<<" cents."<<endl;
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
main()
{
float dollar;
float hour;
float a;
float b;
float c;
printf("your salary is:");
scanf("%f,&dollar);
printf("working hour:");
scanf("%f,&hour);
a=dollar/hour;
b=a-(int)a;
c=a-b;
printf("your average hourly pay rate is %.0f dollars and %.0f cents",c,100*b);
return 0;
}
main()
{
float dollar;
float hour;
float a;
float b;
float c;
printf("your salary is:");
scanf("%f,&dollar);
printf("working hour:");
scanf("%f,&hour);
a=dollar/hour;
b=a-(int)a;
c=a-b;
printf("your average hourly pay rate is %.0f dollars and %.0f cents",c,100*b);
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询