Question

Need this in C#. Revisit the program you developed for Problem 1 of Assignment 2. Now,...

Need this in C#.

Revisit the program you developed for Problem 1 of Assignment 2. Now, you need to satisfy the following additional requirement. If the user enters a number out of range (e.g., non-positive value), the program displays a warning message about the invalid. The program keeps displaying the warning message until the user enters valid inputs. Use loop statement(s).

Here is my code for Problem1 of Assignment 2:

using System;

namespace Assignment2Problem1
{
class Program
{
static void Main(string[] args)
{
double cashFlow;
double loanAmount;
double loanPeriod;
double interestRate;
double monthlyPayment;

string input;
Console.WriteLine("Please enter your cash flow amount.");
input= Console.ReadLine();
cashFlow = double.Parse(input);

Console.WriteLine("Please enter your loan amount.");
input = Console.ReadLine();
loanAmount = double.Parse(input);

Console.WriteLine("Please enter the length of the loan period.");
input = Console.ReadLine();
loanPeriod = double.Parse(input);

Console.WriteLine("Please enter your interest rate.");
input = Console.ReadLine();
interestRate = double.Parse(input);

monthlyPayment = (loanAmount * interestRate / 100) / (1 - (1) / Math.Pow(1 + interestRate / 100, loanPeriod));

Console.WriteLine("Your monthly interest pay is ${0:F3}", monthlyPayment);

if (monthlyPayment <= 0.5 * cashFlow && cashFlow> 5000)
{
Console.WriteLine("Loan is eligible");
}

else if (monthlyPayment <= 0.5 * cashFlow || cashFlow > 5000)
{
Console.WriteLine("Loan is conditionally eligible");
}
else
{
Console.WriteLine("Loan is not eligible");
}
}
}
}

Homework Answers

Answer #1

Here is the solution,

i have used loop for every entry so that the user do not have to start entering from the beginning.

//your code starts here
using System;

namespace Assignment2Problem1
{
class Program
{
static void Main(string[] args)
{
double cashFlow;
double loanAmount;
double loanPeriod;
double interestRate;
double monthlyPayment;

string input;
while (true)
{
Console.WriteLine("Please enter your cash flow amount.");
input = Console.ReadLine();
cashFlow = double.Parse(input);
// while loop will run until user enters a positive number...
if (cashFlow <= 0)
{
// display error message and continue with the loop
Console.WriteLine("Invalid value entered... please try again.");
// to continue
continue;
}
// if users enters a valid number then break the loop
else break;
}


while (true)
{

Console.WriteLine("Please enter your loan amount.");
input = Console.ReadLine();
loanAmount = double.Parse(input);
// while loop will run until user enters a positive number...
if (loanAmount <= 0)
{
// display error message and continue with the loop
Console.WriteLine("Invalid value entered... please try again.");
// to continue
continue;
}
// if users enters a valid number then break the loop
else break;
}


while (true)
{
Console.WriteLine("Please enter the length of the loan period.");
input = Console.ReadLine();
loanPeriod = double.Parse(input);
// while loop will run until user enters a positive number...
if (loanPeriod <= 0)
{
// display error message and continue with the loop
Console.WriteLine("Invalid value entered... please try again.");
// to continue
continue;
}
// if users enters a valid number then break the loop
else break;

}

while (true)
{
Console.WriteLine("Please enter your interest rate.");
input = Console.ReadLine();
interestRate = double.Parse(input);
// while loop will run until user enters a positive number...
if (interestRate <= 0)
{
// display error message and continue with the loop
Console.WriteLine("Invalid value entered... please try again.");
// to continue
continue;
}
// if users enters a valid number then break the loop
else break;
}


monthlyPayment = (loanAmount * interestRate / 100) / (1 - (1) / Math.Pow(1 + interestRate / 100, loanPeriod));

Console.WriteLine("Your monthly interest pay is ${0:F3}", monthlyPayment);

if (monthlyPayment <= 0.5 * cashFlow && cashFlow > 5000)
{
Console.WriteLine("Loan is eligible");
}

else if (monthlyPayment <= 0.5 * cashFlow || cashFlow > 5000)
{
Console.WriteLine("Loan is conditionally eligible");
}
else
{
Console.WriteLine("Loan is not eligible");
}
}
}
}

// code ends here

here is the sample ouput:-

Thank You.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for...
In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition has more than twice...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults. Modify the Contestant class to contain a field that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant. Child...
Write a program that takes two numbers from the Java console representing, respectively, an investment and...
Write a program that takes two numbers from the Java console representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing a 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10, and 20 years using the following formula: future value = investment * (1 + interest rate)year We will assume that the interest...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… The program should now determine the number of classes, and should do so by generating a unique, random number. Replace taking user input for the number of rooms with a computer generated number...
The Problem Write a C or C++ program which performs specific operations on bits. The user...
The Problem Write a C or C++ program which performs specific operations on bits. The user will specify a value The user can then set, test, or toggle individual bits in the initial value. Input Your program will prompt the user for: An inital value in hexadecimal. This value may be up to 32 bits (eight hexadecimal digits) long. If the user-supplied value is less than eight characters in length, assume the additional digits are zero and are on the...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use...
This is C++ Note, for part 2 of this assignment, you DO NOT NEED to use arrays or vectors. All changes, calculations, etc should be performed in place ( in the file). You may need one or two structures that temporary hold data needed to be displayed, changed, etc. Part 2: Binary Files Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT