Question: // this is task3 code #include #include //Defineing NUM_OPTIONS constant with 6 #define NUM_OPTIONS 6 //STEP:2 //Creating a structure with tag name 'account' struct account

// this is task3 code
#include
#include
//Defineing NUM_OPTIONS constant with 6
#define NUM_OPTIONS 6
//STEP:2
//Creating a structure with tag name 'account'
struct account {
char bank_name[50];
int min_deposit;
float rate;
};
//Declaring an array with size of NUM_OPTIONS constant
struct account options[NUM_OPTIONS];
struct account make_account(char *bank, int min_deposit, float rate);
void print_earnings(float deposit);
int main(int argc, const char *argv[]){
// STEP:6
//pushing the different type of bank details data into options array;
options[0] = make_account("Adelaide Bank", 5000, 2.65f);
options[1] = make_account("BankSA", 10000, 2.45f);
options[2] = make_account("CommBank", 5000, 2.30f);
options[3] = make_account("ING", 10000, 2.85f);
options[4] = make_account("NAB", 5000, 2.40f);
options[5] = make_account("PCCU", 5000, 2.70f);
float amount = 0.0f;
printf("How much do you want to inyest? ");
scanf("%f", &amount);
print_earnings(amount);
return 0;
}
struct account make_account(char *bank, int min_deposit, float rate) {
//STEP:5
//creating a temp variable with type 'account'
struct account temp;
//copying the given bank min_deposit and rate into temp variable
strcpy(temp.bank_name , bank);;
temp.min_deposit = min_deposit;
temp.rate = rate;
//returing the temp variable.So that It can be stored in options array;
return temp;
}
void print_earnings(float deposit){
printf("This is how much you will earn in a year: ");
// Use this format string to help with the printf output of each account
printf("%-14s %14s %14s %12s ", "Institution", "Int. Rate", "Min. deposit", "Earnings");
//STEP:7
int i = 0;
//iterating over options array to calculate and print the earnings of each bank
for(i=0;i float earning = 0; //calculating the earning only if the deposit is greater than the min deposit //otherwise it's zero if(deposit >= options[i].min_deposit) earning = (options[i].rate/100) * deposit; //printing the bank details and calculated earning in a table format using format specifiers printf("%-14s %14.2f %14d %14.2f ", options[i].bank_name, options[i].rate, options[i].min_deposit, earning); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
