Minggu, 23 Maret 2014

3.17

(Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After proccessing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls.

C program:
#include <stdio.h> 
int main(){

    int miles, miles1;

    float gallon, gallon1, average, average_total;

    miles = 0;

    gallon = 0;

    printf("Enter the gallons used (-1 to ends): ");

    scanf("%f", &gallon1);

    while(gallon1 != -1){

         gallon += gallon1;

         printf("Enter the miles driven: ");

         scanf("%d", &miles1);

         miles += miles1;

         average = miles1/gallon1;

         printf("The miles/gallon for this tank was %f\n\n", average);

         average_total = miles/gallon;

         printf("Enter the gallons used (-1 to ends): ");

         scanf("%f", &gallon1);

    }

    printf("\nThe overall average was %f\n", average_total);

    system("pause");

}
 Output:

3.18

(Credit Limit Calculator) Develop a C program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a) Account number
b) Balance at the beginning of the month
c) Total of all items charged by this customer this month
d) Total of all credits applied to this customer's account this month
e) Allowed credit limit
The program should input each of these facts, calculate the new balance (= beginning balance + charges – credits), and determine if the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the costumer's account number,  credit limit, new balance,  and the message "Credit limit exceeded".

C Program:
#include <stdio.h>
int main(){

    int ac_number;

    float beginning, charge, credit, credit_limit, new_balance;

    printf("Enter Account Number: ");

    scanf("%d", &ac_number);

    while(ac_number!=-1){

         printf("Enter beginning balance: ");

         scanf("%f", &beginning);

         printf("Enter total charges: ");

         scanf("%f", &charge);

         printf("Enter total credits: ");

         scanf("%f", &credit);

         printf("Enter credit limit: ");

         scanf("%f", &credit_limit);

         new_balance = beginning + charge - credit;

         if(new_balance > credit_limit){

            printf("Account :\t%d\n", ac_number);

            printf("Credit limit :\t%.2f\n", credit_limit);

            printf("Balance :\t%.2f\n", new_balance);

            printf("Credit Limit Excedeed.\n");

         }

         printf("\n");

         printf("Enter Account Number: ");

         scanf("%d", &ac_number);

    }

    system("pause");
}
Output:

3.19

(Sales Commission Calculator) One large chemical company pays its salespeople on a comission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who selss $5000 worth of chemicals in a week recieves $200 plus 9% of $5000, or total of $650. Develop a program that will input each salesperson's earnings.

C Program:
#include <stdio.h>
 

int main(){

    float sell, total;

    printf("Enter sales in dollars (-1 to end): ");

    scanf("%f", &sell);

    while(sell != -1){

         total = 200 + (sell*9/100);

         printf("Salary is : %.2f\n\n", total);

         printf("Enter sales in dollars (-1 to end): ");

         scanf("%f", &sell);

    }

    system("pause");

}
Output:

3.20

(Interest Calculator) The simple interest on a loan is calculated by the formula: 
interest = principal * rate * days / 365;
The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.

C Program:
#include <stdio.h>
 

int main(){

    float interest, principal, rate;

    int days;

    printf("Enter loan principal (-1 to end): ");

    scanf("%f", &principal);

    while(principal != -1){

         printf("Enter interest rate: ");

         scanf("%f", &rate);

         printf("Enter term of the loan in days: ");

         scanf("%d", &days);

         interest = principal*rate*days/365;

         printf("The interest charges is: %.2f\n\n", interest);

         printf("Enter loan principal (-1 to end): ");

         scanf("%f", &principal);

    }

    system("pause");

}
Output:

3.21

(Salary Calculator) Develop a program that will determine the gross pay for each of several employees. The company pays “straight time” for the first 40 hours worked by each employee and pays “time-and-a-half” for all hours worked in excess of 40 hours. You're given a list of the employees of the company, the number of hours employee worked last week and the hourly rate of each employee. Your program should input this information for each employee, and should determine and display the employee's gross pay.

C Program:
#include <stdio.h>
 

int main(){

    int work, normal, overtime;

    float hourly, salary;

    printf("Enter # of hours worked: ");

    scanf("%d", &work);

    while(work != -1){

         printf("Enter the hourly rate of the worker ($00.00): ");

         scanf("%f", &hourly);

         if(work<=40){

            normal = work*hourly;

            overtime = 0;

         }

         else{

            normal = 40*hourly;

            overtime = (work-40)*(hourly*3/2);

         }

         salary = normal + overtime;

         printf("Salary is: %.2f\n\n", salary);

         printf("Enter # of hours worked: ");

         scanf("%d", &work);

    }

    system("pause");

}
Output:

3 komentar:



  1. Please help me to create a program using C program.
    Credit card determination

    You have initially 100,000.00 credit limit your visa card. The you start shopping over a period of time. Make a program that takes in the initial credit limit , then start accepting amount for every purchase you make . The program deducts from your credit limit everytime you have to use your credit card, until you have reached the lowest maintaining credit limit of 500.00
    *add new limit
    *view balance
    *add purchase/edit purchase
    *exit

    BalasHapus