Write a program that prompts the user for a one-week salary (in dollars) and working hours from the keyboard, which are floating-point numbers, and then calculates and outputs the average salary per hour, as shown in the output format:
Your average hourly pay rate is 7 dollars and 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; printf ("Please enter a week ' s salary (in US dollars for the unit): \ n"); scanf ("%f", &salary);p rintf ("Please enter a week of work time:\n "); scanf ("%f ", &time); avg = Salary/time;a = (int.) Avg;avg = (avg-a) *100;printf (" Your average hourly pay R Ate is%d dollars and%2.0f cents. ", A,AVG); return 0;}
In this case, we need to output integers and fractional parts separately for the obtained results. So first declare an integer variable A, cast the value of AVG, and get the integer part. Then subtract the value of a by the value of AVG, get the fractional part multiply by 100, the output time%2.0f width is 2 decimal point is 0. to output cents.
This article is from the PHP learning blog, so be sure to keep this source http://xtceetg.blog.51cto.com/5086648/1693404
C Language Learning II