Visual C# 5.18 (Credit-Limit Calculator)

This Solution is for the “Credit-Limit Calculator Exercise” of chapter 5 in the textbook; Visual c# How to program 6th edition by Deitel.

//Date: 4/27/17

/*Description:
the program prompts user then reads and stores; account number, balance from the beginning of the month,
the total of all items charged on the card this month, the total of all credits applied this month,
and the allowed credit limit; using sentinel-controlled iteration. The program calculates the new
balance for each processing phase. Determines if the new balance exceeds the inputted
credit limit using an if statement. If so, displays “CREDIT LIMIT EXCEEDED!”.
the program then prompts the user to continue or end the program, then reads input.
Program uses While statement to loop processing phase until sentinel value
is read from user at the end of one of the processing phases, in which
case program terminates.
*/
using System;

class Program
{
static void Main()
{
//initialization phase.
int counter = 1;
int end = 0;
int newbal = 0;

//processing phase
Console.Write(“Please enter your account number: “);
int acctnum = int.Parse(Console.ReadLine());

Console.Write(“Please enter your balance from the beggining of the month: “);
int initbal = int.Parse(Console.ReadLine());

Console.Write(“Please enter the total of all items charged on the card this month: “);
int purchs = int.Parse(Console.ReadLine());

Console.Write(“Please enter the total of all credits applied this month: “);
int credits = int.Parse(Console.ReadLine());

Console.Write(“Please enter the allowed credit limit: “);
int limit = int.Parse(Console.ReadLine());

Console.WriteLine(“\nThank you…\n”);

//calculates the new balance for this processing phase
newbal = initbal + purchs – credits;

//if statement that displays CREDIT LIMIT EXCEEDED! if the new balance exceeds the inputed credit limit.
if (newbal > limit)
{
Console.WriteLine($”CREDIT LIMIT EXCEEDED!”);
}

Console.WriteLine($”\nYour New Balance is {newbal}.”);

//prompts user to continue or end program, then reads input
Console.Write(“\nIf you are finished enter; 2.\n To input another account enter; -1: “);
end = int.Parse(Console.ReadLine());
//loops processing phase until sentinal value is read from user at the end of one of the processing phases
while (end < 1)
{

counter++;//increases counter value by 1

Console.Write(“Please enter your account number: “);
int _acctnum = int.Parse(Console.ReadLine());

Console.Write(“Please enter your balance from the beggining of the month: “);
int _initbal = int.Parse(Console.ReadLine());

Console.Write(“Please enter the total of all items charged on the card this month: “);
int _purchs = int.Parse(Console.ReadLine());

Console.Write(“Please enter the total of all credits applied this month: “);
int _credits = int.Parse(Console.ReadLine());

Console.Write(“Please enter the allowed credit limit: “);
int _limit = int.Parse(Console.ReadLine());

Console.WriteLine(“\nThank you…\n”);
int _newbal = _initbal + _purchs – _credits;

if (_newbal > _limit)
{
Console.WriteLine($”CREDIT LIMIT EXCEEDED!”);
}

Console.WriteLine($”\nYour New Balance is {_newbal}.”);

Console.Write(“\nIf you are finished with your entries enter; 2.\n To input another account enter; -1: “);
end = int.Parse(Console.ReadLine());
}

// termination phase

while (end == 2)
{ end++; }// increases “end” by 1 thus terminating the program

}
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s