Explore BrainMass
Share

# Examples of Loops in C: While-Do, Do-Until and For-Loop

NOTE: C coding is fine. Please explain the process.

Senario: For many years, your Uncle Frank has been running a small landscaping business. Through these years, he acquired many steady clients and knew most of them on a first name basis. Once a month, after completing the work for that day, he would calculate (on the spot) how much the client owed for the month with services rendered each week; he would collect the payment and write a receipt.

His clients were charged various prices. Some clients were given a 10% discount because they were old friends. Some clients were given a \$10.00 discount per lawn because of the amount of their business (5 lawns or more). New clients just paid the regular advertised price of \$35.00 per lawn.

Recently, your uncle has hired some additional help because he has been getting older and can't do all the work like he used to. These employees are good and do a great job on landscaping, but for some reason, they have a hard time collecting payments. Either they forget to get a payment or they quote the wrong amount to the client. Your uncle knows he has to find a solution to this problem quickly; otherwise, he may go bankrupt.

At the next family gathering, your uncle asked you if you knew of any solutions for this problem. Since you are in college and taking a computer course, you know that this problem could easily be solved with the use of a computer.

After discussing this with your uncle, you agree to set up a computer and create a program that would keep track of his clients. It would calculate the bills and print invoices that would be mailed to the clients. It will also keep track of the client payments when they were received.

When the clients received their invoices, they would have 30 days to send in their payment. When the payment was received, the program would update the account to reflect this payment, but if no payment was received, then this month's bill would be added to next month's bill plus a 5% late charge.

#### Solution Preview

Below is a pseudocode in C.
//========================================

// Firs introduce a struct to represent a client, for instance:

static const int MAX_LEN = 100 ;
static const float PRICE = 35.00 ; // price per lawn
static const float DISCOUNT = 0.10 ; // discount amount for friends

struct CLIENT
{
char first_name [MAX_LEN+1] ;
char last_name [MAX_LEN+1] ;
int aob ; // amount of business; 5 lawns or more will get a \$10.00 discount per lawn
int friend ; // 1 - friend, 0 - not friend; friends get 10% discount per lawn
float current_balance;// if no payment was received, this month's bill is added to next month's bill plus a 5% late charge
} ;

void CalculateBill (struct CLIENT* p) ;
void GenerateInvoice (struct CLIENT* p) ;

//======================================
// ...

#### Solution Summary

This solution provides the pseudocode in C.

\$2.19