Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C program problem a: Below is some sample C code. Create the three macros indica

ID: 3742297 • Letter: C

Question

C program problem

a:

Below is some sample C code. Create the three macros indicated with comments.

// Create a macro called RATE with a fixed value of 0.12

#define

// Create a macro called SIMPLE_INTEREST that takes in values principal and time

// and computes the amount of interest generated.

// Hint: simple interest is principal times rate times time (in years).

#define

// Create a macro called AMOUNT that takes in values principal and interest and

// computes the final amount after the interest has been added.

// Hint: principal plus interest.

#define

float principal = 1000.0;

int time = 10;

float simple_interest = SIMPLE_INTEREST(principal, time);

float amount = AMOUNT(principal, simple_interest);

b:

Based on the last question, write the code that would appear after the preprocessor has substituted the macros in the code:

float principal = 1000.0;

int time = 10;

float simple_interest =

float amount =

Explanation / Answer

#include // Create a macro called RATE with a fixed value of 0.12 #define RATE 0.12 // Create a macro called SIMPLE_INTEREST that takes in values principal and time // and computes the amount of interest generated. // Hint: simple interest is principal times rate times time (in years). #define SIMPLE_INTEREST(principal, time) (principal * RATE * time) // Create a macro called AMOUNT that takes in values principal and interest and // computes the final amount after the interest has been added. // Hint: principal plus interest. #define AMOUNT(principal, interest) (principal + interest) int main() { float principal = 1000.0; int time = 10; float simple_interest = SIMPLE_INTEREST(principal, time); float amount = AMOUNT(principal, simple_interest); printf("Simple interest: $%f ", simple_interest); printf("Total amount: $%f ", amount); return 0; }