Print employee ID and monthly salary
C Practice Exercise
Write a C program that accepts an employee's ID, total worked hours in a month and the amount he received per hour. Print the ID and salary (with two decimal places) of the employee for a particular month.
C Code:
#include <stdio.h>
int main() {
char id[10]; // Variable to store employee ID (up to 10 characters)
int hour; // Variable to store working hours
double value, salary; // Variables for hourly salary and total salary
// Prompt user for employee ID
printf("Input the Employees ID(Max. 10 chars): ");
scanf("%s", &id);
// Prompt user for working hours
printf("\nInput the working hrs: ");
scanf("%d", &hour);
// Prompt user for hourly salary
printf("\nSalary amount/hr: ");
scanf("%lf", &value);
// Calculate total salary
salary = value * hour;
// Print employee ID and salary
printf("\nEmployees ID = %s\nSalary = U$ %.2lf\n", id, salary);
return 0;
}
Sample Output:
Input the Employees ID(Max. 10 chars): 0342 Input the working hrs: 8 Salary amount/hr: 15000 Employees ID = 0342 Salary = U$ 120000.00
Flowchart:
![C Programming Flowchart: Print the employee's ID and salary of a particular month](https://www.w3resource.com/w3r_images/c-programming-basic-exercises-flowchart-12.png)
C Programming Code Editor:
Previous: Write a C program that accepts two item’s weight (floating points' values ) and number of purchase (floating points' values) and calculate the average value of the items.
Next: Write a C program that accepts three integers and find the maximum of three.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics