Hello all.
I have coded this program to help calculate the cost of running a car once all individual costs are input. Having found the total it then works out the cost per KM.
This is the program as it stands...
#include <stdio.h>
#include <float.h>
int option;
float litre_rate;
float fuel_rate;
float kilo;
float pet_kilo;
float total;
void menu();
void exit();
void program();
void program()
{
printf("\nPlease input the price of a litre of petrol in pounds: ");
scanf("%f",&litre_rate);
printf("\n %f",litre_rate);
printf("\nPlease input the number of litres of fuel used per kilometre: ");
scanf("%f",&fuel_rate);
printf("\n %f",fuel_rate);
printf("\nPlease input the number of kilometres a week you travel: ");
scanf("%f",&kilo);
printf("\n %f",kilo);
pet_kilo=litre_rate*fuel_rate;
total=kilo*pet_kilo;
if (total<0)
{
printf("\nYou appear to have made an error in your calculation as the result returned is less than 0.");
printf("\nTotal =");
printf("%f",total);
printf("\n");
menu();
}
else
{
printf("\nIt will cost you: ");
printf("%f",total);
printf(" pounds a week.");
printf("\n");
menu();
}
}
void menu()
{
printf("----------Car cost calculation program---------\n");
printf("\nPlease select an option:");
printf("\n1 - Run program");
printf("\n2 - Exit");
printf("\n");
scanf("%d",&option);
if (option<2)
{
program();
}
if (option>1)
{
exit();
}
}
void exit()
{
}
int main(void)
{
menu();
}
The trick is that I need to modify it so that it shows the difference in cost per KM by increasing or decreasing the cost of the fuel by a certain percentage.
I know this is a tall order but can anyone assist in modifying it? I normally wouldnt ask...but I think my brains have gone to sleep :P