All pastes #351524 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-02-12 05:58 UTC
rendered paste body
/*
File: Hmwk2.c
Description: Tests to see if credit has exceeded
Programmer: K. Evans
Helper:  Nicholas J. Krut =)
Last Modified: Feb 10, 2007
*/
   
#include <stdio.h>

int testCustomer()
{
	// Predefine the variables:
	int accnum;
	float bal, charge, cred, lim;

	//  Ask for account number:
	printf("Enter account number (&#8209;1 to end):");
	scanf("%d", &accnum);

	// Catch if they are trying to mess with us and enter a nonreal account number:
	while (accnum < -1)
	{
		// Request account number until it is real:
		printf("Invalid entry.  Enter account number (&#8209;1 to end):");
		scanf("%d", &accnum);
	}	
	// If the account number is -1 return false, ending the program:
	if (accnum == -1)
	 return 0;

	// Request beginning balance:
	printf("\nEnter beginning balance: ");
	scanf("%d", &bal);

	// Ask for total changes:
	printf("\nEnter total charges: ");
	scanf("%d", &charge);

	// Ask for total credits:
	printf("\nEnter total credits: ");
	scanf("%d", &cred);

	//  Ask for credit limit:
	printf("\nEnter credit limit: ");
	scanf("%d", &lim);

	// Give us a divider!
	printf("\n======================================\n");

	// Find out the balance:
	bal = bal + charge - cred;

	//  Check if the balance is over the limit
	if(bal > lim) {
		printf("Account: %d\n", accnum );
		printf("Credit limit: %.2f\n", lim );
		printf("Balance: %.2f\n", bal);
		printf("Credit limit exceeded\n");
	} else {
		printf("Credit limit not exceeded\n");
	}

	// Another divider:
	printf("\n======================================\n");
	return 1;
}

int main()
{
	while(testCustomer() == 1)
	{
		printf("Continuing\n");
		// We're still good
	}
   
	return 0;
}