首页 > 代码库 > Exercise 2.4 Calculating average hourly pay rate
Exercise 2.4 Calculating average hourly pay rate
#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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。