Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void startup_message();
void login_process();
void setup();
void menu_and_startup();
void add_transferees();
void view_transferees();
void remit_money();
void time_display();
void display_information();
void thank_you_message();
int main ()
{
startup_message();
login_process();
menu_and_startup();
return 0;
}
void startup_message()
{
printf("Welcome to the newly introduced smsTransfer© (remittances through SMS text messaging)!\n");
printf("a joint project of PioneerBank and Globe Telecom\n");
printf("NOTES:\n");
printf("1. Both the transferers and the transferees must have active accounts with both companies to take part in this service.\n");
printf("2. If this is your first time using the service, please add your account information immediately after logging into this service.\n\n");
}
void login_process()
{
char username[10];
char correct_username[10];
char second_part_of_correct_username[5];
char firstname[10];
char lastname[20];
long long int cin;
long long int correct_password;
long long int password;
short int attempts=0;
printf("Enter your first name:\n");
scanf("%s",firstname);
strncpy(correct_username,firstname,2);
correct_username[2]='\0';
printf("Enter your last name:\n");
scanf("%s",lastname);
strncpy(second_part_of_correct_username,lastname,3);
second_part_of_correct_username[3]='\0';
strncat(correct_username,second_part_of_correct_username,5);
printf("Enter your Customer Identification Number(CIN):\n");
scanf("%llu",&cin);
correct_password=(cin%10)+1;
printf("Please note that usernames are case sensitive.\n");
printf("Enter username:\n");
scanf("%s",&username);
printf("Enter password:\n");
scanf("%llu",&password);
if ((password==correct_password) && strcmp(username,correct_username)==0)
{
printf("Login successful!\n");
}
if ((password==correct_password) && strcmp(username,correct_username)==0)
{
FILE *file;
file=fopen("account_information.txt","a");
fprintf(file,"%s\t%llu\t",&username,&password);
fclose(file);
}
if ((password==correct_password) && strcmp(username,correct_username)==0)
{
setup();
}
while ((password!=correct_password) || strcmp(username,correct_username)!=0)
{
printf("\nThe login details are invalid.Please try again.\n");
printf("Enter username:\n");
scanf("%s",&username);
printf("Enter password:\n");
scanf("%llu",&password);
attempts++;
if (attempts>=5)
printf("Too many failed login attempts. Please re-enter the program and attempt to complete the login process again.\n");
if (attempts>=5)
exit(0);
if ((password==correct_password) && strcmp(username,correct_username)==0)
printf("Login successful!\n");
if ((password==correct_password) && strcmp(username,correct_username)==0)
{
FILE *file;
file=fopen("account_information.txt","a");
fprintf(file,"%s\t%llu\t",&username,&password);
fclose(file);
}
if ((password==correct_password) && strcmp(username,correct_username)==0)
setup();
}
}
void setup()
{
char response;
float current_balance;
printf("Is this your first time using this service?\n");
printf("Enter 'y' for yes or 'n' for no.\n");
scanf("%c",&response);
if (response=='y')
printf("Enter the desired amount from the chequing account to be accessible by this service:$\n");
if (response=='y')
scanf("%f",¤t_balance);
else
current_balance=0;
printf("%.2f",current_balance);
}
void menu_and_startup()
{
short int option;
do
{
printf("\n___________________________________________\n");
printf("1. Add transferees\n");
printf("2. View current transferee list\n");
printf("3. Remit money\n");
printf("4. Account information and settings\n");
printf("5. Exit the application\n");
printf("____________________________________________\n");
printf("Please choose from the above options: \n");
scanf("%d",&option);
switch(option)
{
case 1: add_transferees();
break;
case 2: view_transferees();
break;
case 3: remit_money();
break;
case 4: display_information();
break;
case 5: thank_you_message();
exit(0);
}
} while(option>0 && option<6);
}
void add_transferees()
{
FILE *file;
int i;
char firstName[32];
char lastName[32];
char email_address[40];
long long int account_number;
long int phone_number;
short int addchoice;
int found = 0;
file = fopen("transferee_list.txt", "a");
if (!file)
{
printf("File could not be opened\n\a\a");
getchar();
exit(-1);
}
printf("Enter number of transferees you wish to add:\n");
scanf("%d",&addchoice);
for (i = 0; i<addchoice; ++i)
{
printf("Transferee #%d\n", i+1);
printf("Enter first name:\n"); scanf("%s", &firstName);
printf("Enter last name:\n"); scanf("%s", &lastName);
printf("Enter PioneerBank account number:\n"); scanf("%llu", &account_number);
printf("Enter e-mail address:\n"); scanf("%s", &email_address);
printf("Enter Globe Telecom phone number:\n"); scanf("%lu",&phone_number);
printf("\n");
fprintf(file, "%s\t%s\t%llu\t%s\t%lu\n", firstName, lastName,account_number,email_address,phone_number);
}
printf("Transferee list successfully updated!\n");
fclose(file);
}
void view_transferees()
{
char firstName[32];
char lastName[32];
char email_address[40];
long long int account_number;
long int phone_number;
int counter=0;
int found=0;
FILE *file;
file = fopen("transferee_list.txt", "r");
if (!file)
{
printf("File could not be opened\n\a\a");
exit(-1);
}
while (fscanf(file, "%s\t%s\t%llu\t%s\t%lu", &firstName,&lastName,&account_number,&email_address,&phone_number)==5)
{
printf("Transferee #%d:\n First Name:%s\n Last Name:%s\n Account Number:%llu\n E-mail address:%s\n Phone Number:%lu\n", counter, firstName, lastName, account_number, email_address, phone_number);
found = 1;
}
if (!found)
printf("Record could not be found");
fclose(file);
}
void remit_money()
{
float current_balance;
float transfer_amount;
char transferee_name[70];
printf("\nCurrent smsTransfer© balance:%.2f",current_balance);
printf("Please enter the transferee's legal name (first & last only):");
fgets(transferee_name,60,stdin);
printf("Please enter the transferee's phone number:");
printf("\nEnter the desired transfer amount:$");
scanf("%.2f",&transfer_amount);
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
current_balance-=transfer_amount;
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
printf("Transaction approved! Your current balance is now $%.2f",current_balance);
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
time_display();
while (transfer_amount>=5000)
{
printf("In accordance with the Mobile Banking Act of 2024, customers are prohibited from sending amounts in excess of $1,000 per transaction.");
printf("\nEnter the desired transfer amount:$");
scanf("%.2f",&transfer_amount);
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
current_balance-=transfer_amount;
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
printf("Transaction approved! Your current balance is now $%.2f",current_balance);
if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
time_display();
}
}
void time_display()
{
time_t rawtime;
struct tm *info;
char buffer[80];
time(&rawtime);
info = localtime(&rawtime);
strftime(buffer,80,"%A %B %d,%Y %H:%M (%Z)", info);
printf("Transaction completed on: %s\n", buffer);
}
void display_information()
{
short int view_option;
char address[150];
long long int home_phone_number;
long long int mobile_phone_number;
}
void thank_you_message()
{
printf("Thanks for choosing and using smsTransfer©!\n");
}