Answer to Question #322550 in C# for Madhu

Question #322550

Iterative Simple Interest Calculator


Write a C# program to calculate simple interest.

The program should take the inputs for simple interest and display the result.

The program should ask the user to input Y if he wants to continue, else N to stop

Every time user enters Y, the program should take the inputs and calculate interest


1
Expert's answer
2022-04-02T09:59:03-0400
using System;

namespace simple_interest
{
    class Program
    {
        public static void Main(string[] args)
        {
            int amount, symbol;
            double interest;
            symbol = 0;
            while (Convert.ToChar(symbol) != 'N')
            {
                Console.Write("Enter amount: ");
                amount = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter interest: ");
                interest = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine();
                Console.WriteLine("Interest: {0:f2}", ((amount * interest)/100));
                Console.WriteLine("Total: {0:f2}", (amount +((amount * interest)/100)));
                
                Console.WriteLine("\nInput 'Y' to continue, 'N' to stop");
                symbol = Console.Read();
                Console.ReadLine();
                while ((Convert.ToChar(symbol) != 'N')&(Convert.ToChar(symbol) != 'Y'))
                {
                    Console.WriteLine("\nInvalid input.\nInput 'Y' to continue, 'N' to stop");
                    symbol = Console.Read();
                    Console.ReadLine();
                }
            }
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS