C Parking Ticket System

Verified

Added on  2019/09/26

|7
|581
|173
Practical Assignment
AI Summary
This assignment presents a C program designed to simulate a parking ticket system. The program prompts the user to input the parking duration in hours and minutes. It then calculates the parking charges based on a tiered system: free for less than 20 minutes, RM2 for 1-3 hours (with additional RM1 for each extra hour), and RM5 for more than 3 hours. The program further simulates the payment process, accepting only RM1, RM5, and RM10 notes, and providing feedback on the remaining balance. Finally, it offers the option to print a receipt. The code includes input validation to ensure the user enters valid note denominations. The solution demonstrates fundamental C programming concepts such as conditional statements, loops, input/output operations, and basic error handling.
Document Page
Unit Co-ord./Lecturer OFFICE USE ONLY
Assignment received:
Tutor:(if applicable)
Student ID
Student Name
Unit Code
Unit Name
Assignment
Title/Number
Word Count
I declare that all material in this assignment is my own work except where there is clear acknowledgement or reference to
the work of others and I have complied and agreed to the University statement on Plagiarism and Academic Integrity on the
University website at www.utas.edu.au/plagiarism *
Signed Date
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
C Program:
#include<stdio.h>
void main()
{
int hours=0, minutes=0;
int totalbill=0, totalpaid=0;
int rm;
char choice;
printf("\t\ttB J PARKING TICKET SYSTEM\n\n");
printf("Insert Parking Ticket\n");
//prompt for input hours
printf("Enter Hour >>");
scanf("%d", &hours);
// prompt for input minutes
printf("Enter Minutes >>");
scanf("%d", &minutes);
printf("\n\nDuration parking: %d hours %d minutes\n",
hours, minutes);
if(hours == 0 && minutes <=20)
{
//condition for less than 20 minutes
totalbill=0;
}
else if( hours >= 1 && hours <= 3 )
{
//condition for 1-3 hours
if(minutes == 0)
{
totalbill = 2+(hours-1)*1;
}
else
{
totalbill = 2+(hours+1-1)*1;
}
Document Page
}
else
{
// condition for greater than 3 hours
totalbill=5;
}
printf("Parking Charges : RM %d.0\n\n", totalbill);
// start paying bill
while(totalbill>0)
{
// show bill and prompt to input notes
printf("Please insert payment RM%d.0 >> ",
totalbill);
scanf("%d", &rm);
// checking for valid notes
if(rm == 10 || rm == 5 || rm == 1)
{
// adding in amount paid
totalpaid=totalpaid+rm;
// deducting from total bill
totalbill=totalbill-rm;
printf("Total RM%d.0\n\n", totalpaid);
if(totalbill<0)
{
printf("Balance is RM%d.0\n\n", 0-
totalbill);
}
}
else
{
// prompt for invalid notes
printf("\nInvalid note provided. Please enter
only RM10.0, RM5.0 or RM1.0 notes\n\n");
continue;
}
}
fflush(stdin);
Document Page
printf("wait for parking ticket to be printed out\n\
n");
printf("Do you want a receipt >> ");
// first scanf is just to empty input buffer
scanf("%c", &choice);
// input choice for receipt print
scanf("%c", &choice);
if(choice=='Y')
{
printf("Printing receipt\n\n");
}
printf("Thank You\n");
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Document Page
Document Page
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]