-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSchool Billing System.c
101 lines (92 loc) · 3.24 KB
/
School Billing System.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 50
#define MAX_NAME_LENGTH 50
typedef struct {
int studentID;
char studentName[MAX_NAME_LENGTH];
double tuitionFee;
double payment;
} Student;
Student students[MAX_STUDENTS];
int totalStudents = 0;
void addStudent(int studentID, const char *studentName, double tuitionFee) {
if (totalStudents < MAX_STUDENTS) {
students[totalStudents].studentID = studentID;
strcpy(students[totalStudents].studentName, studentName);
students[totalStudents].tuitionFee = tuitionFee;
students[totalStudents].payment = 0;
totalStudents++;
printf("Student added successfully.\n");
} else {
printf("Maximum student limit reached.\n");
}
}
void makePayment(int studentID, double amount) {
for (int i = 0; i < totalStudents; i++) {
if (students[i].studentID == studentID) {
students[i].payment += amount;
printf("Payment of %.2f made for student %s.\n", amount, students[i].studentName);
return;
}
}
printf("Student with ID %d not found.\n", studentID);
}
void generateBill(int studentID) {
for (int i = 0; i < totalStudents; i++) {
if (students[i].studentID == studentID) {
double balance = students[i].tuitionFee - students[i].payment;
printf("Student: %s\n", students[i].studentName);
printf("Tuition Fee: %.2f\n", students[i].tuitionFee);
printf("Payment Made: %.2f\n", students[i].payment);
printf("Balance: %.2f\n", balance);
return;
}
}
printf("Student with ID %d not found.\n", studentID);
}
int main() {
int choice;
do {
printf("\nSchool Billing System\n");
printf("1. Add Student\n");
printf("2. Make Payment\n");
printf("3. Generate Bill\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
int studentID;
char studentName[MAX_NAME_LENGTH];
double tuitionFee;
printf("Enter student ID: ");
scanf("%d", &studentID);
printf("Enter student name: ");
scanf("%s", studentName);
printf("Enter tuition fee: ");
scanf("%lf", &tuitionFee);
addStudent(studentID, studentName, tuitionFee);
break;
case 2:
printf("Enter student ID: ");
scanf("%d", &studentID);
double paymentAmount;
printf("Enter payment amount: ");
scanf("%lf", &paymentAmount);
makePayment(studentID, paymentAmount);
break;
case 3:
printf("Enter student ID: ");
scanf("%d", &studentID);
generateBill(studentID);
break;
case 4:
printf("Exiting the system.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}