0% found this document useful (0 votes)
28 views2 pages

Lec 02

Intro to programming course of must

Uploaded by

Majeed Waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Lec 02

Intro to programming course of must

Uploaded by

Majeed Waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

// Define a maximum interest rate.

int maximumInterest = 50;

// Prompt user to enter source principal.

Console.Write(“Enter principal: “);

string principalInput = Console.ReadLine();

decimal principal = Convert.ToDecimal(principalInput);

// If the principal is negative . . .

if (principal < 0)

// . . . generate an error message . . .

Console.WriteLine(“Principal cannot be negative”);

else // Go here only if principal was > 0: thus valid.

// . . . otherwise, enter the interest rate.

Console.Write(“Enter interest: “);

string interestInput = Console.ReadLine();

decimal interest = Convert.ToDecimal(interestInput);

// If the interest is negative or too large . . .

if (interest < 0 || interest > maximumInterest)

// . . . generate an error message as well.

Console.WriteLine(“Interest cannot be negative “ +

“or greater than “ + maximumInterest);

interest = 0;

else // Reach this point only if all is well.

// Both the principal and the interest appear to be legal;


// calculate the value of the principal plus interest.

decimal interestPaid;

interestPaid = principal * (interest / 100);

// Now calculate the total.

decimal total = principal + interestPaid;

// Output the result.

Console.WriteLine(); // Skip a line.

Console.WriteLine(“Principal = “ + principal);

Console.WriteLine(“Interest = “ + interest + “%”);

Console.WriteLine();

Console.WriteLine(“Interest paid = “ + interestPaid);

Console.WriteLine(“Total = “ + total);

// Wait for user to acknowledge the results.

Console.WriteLine(“Press Enter to terminate . . . “);

Console.Read();

You might also like