C Language Learning II

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.