0% found this document useful (0 votes)
28 views4 pages

GROUP 8 Code

Mobile bill generation code

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

GROUP 8 Code

Mobile bill generation code

Uploaded by

Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>

// Maximum customers
int MAX_CUSTOMERS = 100;

// Global variables
int customerCount = 0;
int customerID[100];
char name[100][50];
char phoneNumber[100][15];
int callMinutes[100];
oat billAmount[100];

// Function to check if a customer already exists


int isDuplicate(int id, char customerName[], char phone[])
{
for (int i = 0; i < customerCount; i++)
{
if (customerID[i] == id)
{
printf("Error: Customer with ID %d already exists.\n", id);
return 1;
}
int j = 0;
while (name[i][j] != '\0' && customerName[j] != '\0' && name[i][j] == customerName[j])
{
j++;
}
if (name[i][j] == '\0' && customerName[j] == '\0')
{
printf("Error: Customer with name '%s' already exists.\n", customerName);
return 1;
}

j = 0;
while (phoneNumber[i][j] != '\0' && phone[j] != '\0' && phoneNumber[i][j] == phone[j])
{
j++;
}
if (phoneNumber[i][j] == '\0' && phone[j] == '\0')
{
printf("Error: Customer with phone number '%s' already exists.\n", phone);
return 1;
}
}
return 0;
}

// Function to add a customer


int addCustomer()
{
if (customerCount >= MAX_CUSTOMERS)
{
printf("Customer limit reached! Cannot add more customers.\n");
return 0;
}

int id;
char customerName[50], phone[15];
int minutes;
fl
printf("Enter Customer ID: ");
scanf("%d", &id);
printf("Enter Customer Name: ");
scanf(" %[^\n]s", customerName);
printf("Enter Phone Number: ");
scanf("%s", phone);
printf("Enter Call Minutes: ");
scanf("%d", &minutes);

// Check for duplicates


if (isDuplicate(id, customerName, phone))
{
return 0; // Do not add duplicate
}

// Add customer details


customerID[customerCount] = id;
int i = 0;
while (customerName[i] != '\0')
{
name[customerCount][i] = customerName[i];
i++;
}
name[customerCount][i] = '\0'; // Null terminate the string

i = 0;
while (phone[i] != '\0')
{
phoneNumber[customerCount][i] = phone[i];
i++;
}
phoneNumber[customerCount][i] = '\0'; // Null terminate the string

callMinutes[customerCount] = minutes;

// Calculate bill amount


oat ratePerMinute = 1.50; // Example rate: $1.50 per minute
billAmount[customerCount] = callMinutes[customerCount] * ratePerMinute;

customerCount++;
printf("Customer added successfully!\n");
return 0;
}

// Function to view all customers


int viewCustomers()
{
if (customerCount == 0)
{
printf("No customers to display.\n");
return 0;
}

printf("\nCustomer List:\n");
printf("ID\tName\t\tPhone\t\tCall Minutes\tBill Amount\n");
printf("-------------------------------------------------------------\n");
for (int i = 0; i < customerCount; i++)
{
printf("%d\t%s\t\t%s\t\t%d\t\t$%.2f\n",
fl
customerID[i],
name[i],
phoneNumber[i],
callMinutes[i],
billAmount[i]);
}
return 0;
}

// Function to calculate the bill for a speci c customer


int calculateBill()
{
int id, found = 0;
printf("Enter Customer ID to calculate bill: ");
scanf("%d", &id);

for (int i = 0; i < customerCount; i++)


{
if (customerID[i] == id)
{
printf("Customer: %s\n", name[i]);
printf("Phone: %s\n", phoneNumber[i]);
printf("Call Minutes: %d\n", callMinutes[i]);
printf("Bill Amount: $%.2f\n", billAmount[i]);
found = 1;
break;
}
}

if (!found)
{
printf("Customer with ID %d not found.\n", id);
}
return 0;
}

// Main function
int main()
{
int choice;

do
{
printf("\n*** Mobile Billing System ***\n");
printf("1. Add Customer\n");
printf("2. View All Customers\n");
printf("3. Calculate Bill for a Customer\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

if (choice == 1)
{
addCustomer();
}
else if (choice == 2)
{
viewCustomers();
}
else if (choice == 3)
fi
{
calculateBill();
}
else if (choice == 4)
{
printf("Exiting the system. Thank you!\n");
}
else
{
printf("Invalid choice! Please try again.\n");
}
} while (choice != 4);

return 0;
}

You might also like