首页 > Web开发 > 详细

Exercise 2.4 Calculating average hourly pay rate

时间:2014-12-17 00:05:39      阅读:344      评论:0      收藏:0      [点我收藏+]
 #include <stdio.h>
 int main (void) 
 {
     double pay = 0.0;
     double hours = 0.0;
     int dollars = 0;
     int cents = 0;
     
     //ger the weekly pay
     printf ("Enter your weekly pay in the dollars:");
     scanf ("%lf", pay);
     
     //get the weekly hours
     printf ("Enter your hours worked");
     scanf ("%lf", hours);
     
     //calculate the average hourly rate -dollars first
     dollars = (int)(pay)/(hours);
     
     //get the cents :subtract the dollars from the hours rate and then multiply by 100 to get the cents
     // If we then add 0.5 and convert the result back to an integer , it will be th nearest cent. 
     cents = (int)(100*(pay/hours - dollars) + 0.5);
     
     //output the average houly rate
     printf ("%d dollars %d cents", dollars, cents) ;
     return 0;
 }

 

Exercise 2.4 Calculating average hourly pay rate

原文:http://www.cnblogs.com/xiaomi5320/p/4168239.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!