Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
1
Indexable
Never
#include <stdio.h>

// REFERENCE FOR ALIGNING NUMBERS USING printf()
// https://www.eecis.udel.edu/~sprenkle/cisc105/making_columns.html

int main() {
    double total_salary = 0, total_raise = 0, total_newsalary = 0;
    double salary, raise, new_salary = 0;
    float rate;
    // EXPLAINATION:
    // printf("%25.2lf%15.2lf%15.2lf%15.2lf\n", salary, rate, raise, new_salary);
    //      Let's break down the above line:
    //      %25.2lf   %15.2lf   %15.2lf   %15.2lf
    //
    // printf("                   Salary           Rate          Raise     New Salary\n");
    //      Let's break down the above line:
    // "                   Salary" => 25 characters  => so we have %25.2lf
    // "           Rate" => 15 characters  => so we have %15.2lf
    // "          Raise" => 15 characters  => so we have %15.2lf
    // "     New Salary" => 15 characters  => so we have %15.2lf

    printf("                   Salary           Rate          Raise     New Salary\n");
    printf("----------------------------------------------------------------------\n");
    while (1){
        printf("Salary: ");
        scanf("%lf", &salary);
        if(salary < 0)
        break;
        if(salary < 30000)
         {
             rate = 7.0;
        } else if(salary <= 40000)
        {
            rate = 5.5;
        } else
        {
            rate = 4.0;
        }

        raise = (rate / 100) * salary;
        new_salary = salary + raise;

        total_salary += salary;
        total_newsalary += new_salary;
        total_raise += raise;

        printf("%25.2lf %15.2lf %15.2lf %15.2lf\n", salary, rate, raise, new_salary);
    }
    printf("----------------------------------------------------------------------\n");
    printf("Total%20.2lf%30.2lf%15.2lf\n", total_salary, total_raise, total_newsalary);

    return 0;
}