carrental

carrental - fuel_cost + car_cost);...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Script started on Fri Mar 11 09:59:48 2005 %cat c53fuel.c #include<stdio.h> #define COMPACT_PER_DAY 10.00 #define REGULAR_PER_DAY 20.00 #define FUEL_COST_COMPACT 1.00 #define FUEL_COST_REGULAR 1.50 #define MPG_COMPACT 20.0 #define MPG_REGULAR 15.0 void calc_fuel (char type_car, double miles_driven, double *fuel_cost); void calc_daily (char type_car, int days, double *car_cost); int main(void){ char type_car; double miles_driven,car_cost,fuel_cost; int days,id,flag; fuel_cost = 0.0; printf("id type car DAYS miles driven fuel cost car cost"); printf("total cost\n"); flag=scanf("%d",&id); while (flag !=EOF){ scanf(" %c %lf %d",&type_car,&miles_driven,&days); calc_fuel (type_car,miles_driven,&fuel_cost); calc_daily (type_car,days, &car_cost); printf("%d %c %5d %16.2f %10.2f %10.2f %10.2f\n", id,type_car, days, miles_driven,fuel_cost,car_cost,
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fuel_cost + car_cost); flag=scanf("%d",&id);} return (0);} void calc_fuel (char type_car, double miles_driven, double *fuel_cost){ if (type_car == 'C' || type_car == 'c') *fuel_cost = miles_driven/MPG_COMPACT * FUEL_COST_COMPACT; else *fuel_cost = miles_driven/MPG_REGULAR * FUEL_COST_REGULAR; return;} void calc_daily (char type_car,int days, double *car_cost){ if (type_car == 'c' || type_car == 'C') *car_cost = days * COMPACT_PER_DAY; else *car_cost = days * REGULAR_PER_DAY; return; } %gcc c53fuel.c %a.out < fuel id type car DAYS miles driven fuel cost car costtotal cost 123 R 3 100.00 10.00 60.00 70.00 124 C 2 50.00 2.50 20.00 22.50 125 c 3 100.00 5.00 30.00 35.00 126 C 4 200.00 10.00 40.00 50.00 %exit exit Script done on Fri Mar 11 10:00:09 2005...
View Full Document

This note was uploaded on 12/01/2011 for the course CSC 1253 taught by Professor Staff during the Fall '08 term at LSU.

Ask a homework question - tutors are online