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
5 changes: 5 additions & 0 deletions assignment6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. The output will be 203 1 23 because the other integers will be invalid.

1. structure and enumeration are two different data types. Structure can store every types of variables while enumeration can only store integers. Enumeration is mostly used to define terms while structure actually assigns specific values.

2. The difference is that: if the array is passed directly, the value of the array will be changeable while if the array is passed through a structure, the value will not be changeable anywhere other than the target location.
53 changes: 53 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//Justin Yu My code contains errors that I can't troubleshoot //

#include <stdio.h>
#include <string.h>


typedef struct bank {

char name[100];
int accountNumber;
float balance;
} bank;

int deposit (int initial, int cash) {

initial = initial + cash;
printf("The new balance is %d\n", initial);
}

int withdraw (int initial, int cash) {

initial = initial - cash;
printf("The new balance is %d\n", initial);
}

int main() {
int input;
int amount;

bank peter = {999, "Peter", 96};
bank caleb = {119, "Caleb", 24};

printf("Would you like to deposit or withdraw? 1.deposit 2.withdraw \n");
scanf("%d", &input);

if(input == 1) {
printf("amount?\n");
scanf("%d", amount);
deposit(amount, peter);}

else if(input == 2) {
printf("amount?\n");
scanf("%d", amount);
withdraw(amount, peter);}

printf("%f", bank.balance);

}





37 changes: 37 additions & 0 deletions calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>

int main() {

int variable1;
int calculation;
int variable2;
int output;

printf("Enter a variable\n");
scanf("%d", &variable1);

printf("indicate which type of calculation you want to perform, input 1 for addition, 2 for subtraction, 3 for multiplication, 4 for division\n");
scanf("%d", &calculation);

printf("Enter another variable\n");
scanf("%d", &variable2);

if(calculation == 1) {
output = variable1 + variable2;
printf("%d\n",output); }
else if(calculation == 2) {
output = variable1 - variable2;
printf("%d\n",output); }
else if(calculation == 3) {
output = variable1 * variable2;
printf("%d\n",output); }
else if(calculation == 4) {
output = variable1 / variable2;
printf("%d\n",output); }
else {
printf("invalid calculation type\n");}

return 0;
}


40 changes: 40 additions & 0 deletions student.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//Justin Yu This code is designed to present the average grades of five students//

#include <stdio.h>
#include <string.h>

typedef struct student {
char name[100];
int age;
int scores[5];
} student;

float average (float average) {
average = 0;
int i;

for(i = 0; i < 5; i++) {
average += student.scores[i];
}
average /= 5;

printf("%s, average: %f", student.name, average);


int main() {

struct student s1 = {"Caleb", 17, {89,90,91,92,93}};
struct student s2 = {"Peter", 17, {91,92,93,94,95}};
struct student s3 = {"Sam", 18, {93,94,95,96,97}};
struct student s4 = {"Andrew", 16, {94,95,96,97,98}};
struct student s5 = {"Justin", 16, {96,97,98,99,100}};

struct student student[] = {s1,s2,s3,s4,s5};

for(int i = 0; i < 5; i++) {
avg(student[i]);
printf("\n");
}

}