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;
 }
时间: 2024-12-28 11:23:56

Exercise 2.4 Calculating average hourly pay rate的相关文章

bugkExercise 5.5 Calculating average student grades.

从输出结果来看,这个程序是错的.完全不知道什么意思. Exercise 5-5. Write a program that will calculate the average grade for the students ineach of an arbitrary number of classes. the program should read in all the grades forstudents in all classes before calculating the aver

Exercise 2.3 Calculating volume price of alternative products

// Exercise 2.3 Calculating volume price of alternative products // The only problem here is to devise a way to determine the price // for the product type. Here I used the product type value to do this. #include <stdio.h> int main(void) { double to

Exercise 2.2 Calculating the area of a room

#include <stdio.h> int main(void) { long feet = 0L; long inches = 0L; double length = 0.0; double width = 0.0; const long inches_per_feet = 12L; const double inches_per_yard = 36L; // get the length of the room printf("Enter the length in foot

c语言学习二

编写一个程序,提示用户从键盘输一个星期的薪水(以美元为单位)和工作时数,它们均为浮点数,然后计算并输出每个小时的平均薪水,输出格式如下所示: Your average hourly pay rate is 7 dollars and 54 cents. #include <stdio.h> int main(int argc, char** argv) { float salary = 0.0f; float time = 0.0f; float avg = 0.0f; int a = 0;

java语言程序设计基础课后习题第二章

1 //exercise 2.2 2 package secondchapterexercise1; 3 4 public class first01 { 5 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 double miles=100; 9 double KILOMETERS_PER_MILE=1.609; 10 double kilometers=miles*KILOMET

《java 语言程序设计》第2章编程练习

2.1 public class test { public static void main(String[] args) { Scanner input = new Scanner(System.in); double f, c; c = input.nextDouble(); f = (9.0/5)*c+32; System.out.println(f); } } 2.2 public class test { public static void main(String[] args)

HW2.11

控制台: 1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 System.out.print("Enter employee's name: "); 10 String name = input.nextLine(); 11 12 Syste

Java性能提示(全)

http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLists and ArrayLists (and Vectors) (Page last updated May 2001, Added 2001-06-18, Author Jack Shirazi, Publisher OnJava). Tips: ArrayList is faster than

Radio Basics for RFID

Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09/24 22:30:37) Radio Basics for RFID (2015/09