/* petrol.c */ /* works out miles per gallon, pence per mile etc. */ main() { float cost, miles, pperl, litres; printf("Hi there, I work out how efficient your car is.\n\n"); printf("To put in the correct figures, you must first fill your car all\n"); printf("the way up with fuel and re-set your trip counter. The next time\n"); printf("you fill up, again fill up all the way, and note down how much\n"); printf("fuel you bought in litres, the cost per litre, and how many miles\n"); printf("you did since your last fill-up.\n\n\n"); printf("Enter the amount in pounds you spent on fuel: "); scanf("%f",&cost); printf("What is the cost in pence per litre: "); scanf("%f",&pperl); printf("And how many miles you did since your last fill-up: "); scanf("%f",&miles); printf("\n\n\n"); litres = cost / (pperl/100); printf("Your car does %.1f miles to the gallon.\n",miles/(litres * 0.21199)); printf("Or %.1f miles to the litre.\n",miles/litres); printf("It costs you %.2f pence per mile.\n",(cost*100)/miles); printf("\n\n(Press any key to exit.)"); getch(); }