Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Assignment6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Clarke Littlejohn
This mist likely has a lot of typos as i was extremely tried when doing this.

1) if i recall correctly it shouldnt print anything as the unassigned int have a special % thing
but if that is not it then it print out the 8 1 7 as those are predefined. but i would think it would crash.

2)structes and enum are similiar at all really. enums from what i know seem goot for calendars and thats it
where structures are seem very similiar to objects in java or c++ which makes them much more useful. enums to me seems pointless it like an
array but instead f x[0] you can call it by a name.

3)passing an array directly passes it by reference so it makes so that it it can changed wuth un that function and the chnages will stay
whereas the a struct that has an array and that is being passed is passed by value. Si a copied is made and any changes that are made are
done in the original array.
192 changes: 192 additions & 0 deletions bank.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
//Clarke Littlejohn
//Banking program
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

typedef struct{
int ID;
float balance;
char fName[100];
char lName[100];
char password[100];
}bankAcc;
void accountSetup(char);
float deposit(char[],bankAcc);
float withdraw(char[],bankAcc);
void updateInfo(bankAcc);
void menu();

int main(){
accountSetup('i');
return 0;
}
void accountSetup(char dw){

srand(time(0));
int temp=0;
char input[3], input1[100];
static bankAcc user;

//i couldn't think of any other way to make sure the values were being passed correctly since the user is declared here
if(dw=='D'||dw=='W'||dw=='Q')
goto DWQ;

//gets user input to see if the person wants to set up an account
printf("Bank\n");
do{
printf("Do you want to set up an account? [Y/N] ");
if(temp>0)
printf("\nEnter Y for yes N for no. ");
fgets(input,sizeof(input),stdin);
input[strlen(input)-1]='\0';
if(strcmp(input,"Y")==0){
break;
}
else {
if(strcmp(input,"N")==0){
printf("Ending program...\n");
return;
}
}
temp++;
}while(1);

//these 3 blocks of code get the name and password of the account.
//could have done this in a 2D array but i was too lazy to look up how to print 2d arrays.
printf("\nEnter your first name: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
strcpy(user.fName,input1);

printf("\nEnter your last name: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
strcpy(user.lName,input1);

printf("\nEnter your Password: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
strcpy(user.password,input1);

//confirmation on password.
int tracker=0;
do{
if(tracker==0)
printf("\nConfirm your Password: ");
else
printf("Password does not match. Confirm your Password: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
if(strcmp(user.password,input1)==0)
break;
tracker++;
}while(1);

user.ID=rand();
printf("Your ID number is: %d",user.ID);
menu();

//skips over the code aboce as that only needs to be done once
DWQ: if(dw=='D'){
printf("\nEnter your Password: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
user.balance=deposit(input1,user);
updateInfo(user);
menu();
} else if(dw=='W'){
printf("\nEnter your Password: ");
fgets(input1,sizeof(input1),stdin);
input1[strlen(input1)-1]='\0';
user.balance=withdraw(input1,user);
updateInfo(user);
menu();
} else if(dw=='Q'){
updateInfo(user);
printf("\nEnding Program...\n");
}

}


void menu(){
char input[3];
int i=1;
//get the type of transaction was going to add more things to the menu
do
{
printf("\nWhat transaction would you like to do?\n(D)Deposit, (W)Withdraw, or (Q)Quit: ");

fgets(input,sizeof(input),stdin);
input[strlen(input)-1]='\0';
if(input[0]=='D' || input[0]=='W' || input[0]=='Q'){
accountSetup(input[0]);
i=0;

}
}while(i);
}

float deposit(char password[], bankAcc user){

//makes sure the password is correct before entering it, there should be some type of lock or cooldown period but can think of a way to
//code that.
char userError [100];
float money=0;
if(strcmp(user.password,password)!=0){
while(strcmp(user.password,userError)!=0){
printf("\nInvaild password. Reenter your password: ");
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
}
}

//deposits money
printf("\nEnter the amount of money you want to add to your account: ");
scanf("%f",&money);
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
return user.balance+money;
}

float withdraw(char password[], bankAcc user){

//makes sure the password is correct before entering it, there should be some type of lock or cooldown period but can think of a way to
//code that.
char userError [100];
float money=0;
if(strcmp(user.password,password)!=0){
while(strcmp(user.password,userError)!=0){
printf("\nInvaild password. Reenter your password: ");
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
}
}

//withdraws money
printf("\nEnter the amount of money you want to take out of your account: ");
scanf("%f",&money);
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
return user.balance-money;
}

void updateInfo(bankAcc user){
printf("\nName: %s %s\nID Number: %d\nBalance: $%.2f",user.fName,user.lName,user.ID,user.balance);
}














137 changes: 137 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//Clarke Littlejohn
//Banking program i used code from another banking program i wrote so is probably is not as clean as it should be.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>

typedef struct{
int ID;
float balance;
char fName[100];
char lName[100];
}bankAcc;
float deposit(bankAcc);
float withdraw(bankAcc);
void updateInfo(bankAcc);
char menu();

int main(){

srand(time(0));
bankAcc user[2];
user[0].ID=rand();
user[0].balance=10000;
strcpy(user[0].fName,"john");
strcpy(user[0].lName,"doe");
updateInfo(user[0]);


char x;
do{
x=menu();
if(x=='D'){
user[0].balance=deposit(user[0]);
updateInfo(user[0]);
x=menu();
} else if(x=='W'){
user[0].balance=withdraw(user[0]);
updateInfo(user[0]);
x=menu();
} else if(x=='Q'){
updateInfo(user[0]);
printf("\nEnding Program...\n");
}
else
x=menu();
}while(x!='Q');





user[1].ID=rand();
user[1].balance=23234;
strcpy(user[1].fName,"jane");
strcpy(user[1].lName,"doe");
updateInfo(user[1]);

do{
x=menu();
if(x=='D'){
user[1].balance=deposit(user[1]);
updateInfo(user[1]);
x=menu();
} else if(x=='W'){
user[1].balance=withdraw(user[1]);
updateInfo(user[1]);
x=menu();
} else if(x=='Q'){
updateInfo(user[1]);
printf("\nEnding Program...\n");
}
else
x=menu();
}while(x!='Q');
return 0;
}
char menu(){
char input[3];
int i=1;
//get the type of transaction was going to add more things to the menu
do
{
printf("\nWhat transaction would you like to do?\n(D)Deposit, (W)Withdraw, or (Q)Quit: ");

fgets(input,sizeof(input),stdin);
input[strlen(input)-1]='\0';
if(input[0]=='D' || input[0]=='W' || input[0]=='Q'){
i=0;

}
}while(i);
return input[0];
}

float deposit(bankAcc user){

float money;
char userError[100];

//deposits money
printf("\nEnter the amount of money you want to add to your account: ");
scanf("%f",&money);
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
return user.balance+money;
}
float withdraw(bankAcc user){

float money;
char userError[100];

//withdraws money
printf("\nEnter the amount of money you want to take out of your account: ");
scanf("%f",&money);
fgets(userError,sizeof(userError),stdin);
userError[strlen(userError)-1]='\0';
return user.balance-money;
}

void updateInfo(bankAcc user){
printf("\nName: %s %s\nID Number: %d\nBalance: $%.2f",user.fName,user.lName,user.ID,user.balance);
}














Loading