Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Oil bills system A company for cars oil services asked you to develop a system t

ID: 3713103 • Letter: O

Question

Oil bills system A company for cars oil services asked you to develop a system to compute and display oil consumption bills. The developed system will compute the oil bill based on the car consumption. Your program will have the following main menu: 1-Car information 2- Bills 3- Display bills 4- Exit Please choose from the menu: 1- Car information The first choice will enable the user to insert the car information (ID of the car owner, car number, mobile number of the car owner). For car number, make the user inserts three characters followed by the numerical number (e.g., XYX 1234 will be stored in three characters and one integer number). This information will be saved in cars.txt file Sample output: Insert customer ID: 6584 Insert car number x Y X 1234 Insert customer mobile number: 05123456 Do you want to insert another car (Y/N)? N

Explanation / Answer


#include<stdio.h>
#include<process.h>

int main()
{
FILE *fptr;
char ch;
int choice;
int id,custID,month,year,consumption;
double bill;
char carNo[12];
char mobileNo[10];

fptr=fopen("Bills.txt","w");
if(fptr==NULL)
{
printf("Could not find the file!!");
exit(0);
}

printf("1- Car information 2- Bills 3- Display bills 4- Exit ---------- ");
printf("Please choose from the menu: ");
scanf("%d",&choice);
while(1)
{
switch(choice)
{
case 1:
printf("1- Car information ");
printf("Insert customer ID: ");
scanf("%d",&id);
fprintf(fptr,"%d",id);
printf("Insert car number: ");
gets(carNo);
fprintf(fptr," %s",carNo);
printf("Insert customer mobile number: ");
gets(mobileNo);
fprintf(fptr," %s",mobileNo);
fclose(fptr);
break;

case 2:

printf("Insert customer ID or 0 to go back. ");
scanf("%d",&custID);
if(custID==id)
{
printf("Customer ID: %d ",custID);
}
else
{
printf("Customer is not exist");
}
printf("Month : ");
scanf("%d",&month);
printf("Year : ");
scanf("%d",&year);
printf("Consumption : ");
scanf("%d",&consumption);
if(consumption<10)
{
bill=consumption*10;
}
else if(consumption>=10 && consumption<=20)
{
bill=consumption*8;
}
else if(consumption>=21 && consumption<=55)
{
bill=consumption*6.5;
}
else if(consumption>=56 && consumption<=160)
{
price=consumption*4;
}
else if(consumption>160)
{
bill=consumption*2;
}
printf("The oil bill is : %f ",bill);
fprintf(fptr,"%d %d %d %d %f",custID,month,year,consumption,bill);
fclose(fptr);
break;

case 3:
fptr=fopen("Bills.txt","r");
if(!fptr)
{
printf("file cant read!!");
exit(1);
}
while(fscanf(fptr,"%d %d %d %d %f",&custID,&month,&year,&consumption,&bill) == 1)  
{  
printf("%d %d %d %d %f",custID,month,year,consumption,bill));  
}
fclose(fptr);
break;

case 4:exit(0);
}
printf("Do you want to insert another car (y/n)");
scanf("%c",&ch);
if(ch=='n')
{
break;
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote