Complete the program below, so it works. User enters amount to invest, interest percentage and number of years. Enter amount to invest: 200 Enter interest percentage: 0.10 Enter number of years: 2 Year: 1 Interest: 20 Year: 2 Interest: 20 Total Amount thus far: 220 Total Amount thus far: 240 The while loop runs according to the user
USING C#
Program:
using System;
class Program {
static void Main() {
double amount, interestPerc, interest;
int years, i = 1;
Console.Write("Enter amount to invest: ");
amount = double.Parse(Console.ReadLine());
Console.Write("Enter interest percentage: ");
interestPerc = double.Parse(Console.ReadLine());
Console.Write("Enter number of years: ");
years = int.Parse(Console.ReadLine());
Console.WriteLine();
//calculate interest
interest = amount * interestPerc;
//loop to display amount for given years
while (years > 0){
//add interest in the amount
amount = amount + interest;
Console.Write("Year: " + i + " Interest: " + interest + " Total Amount Thus Far: " + amount);
Console.WriteLine();
years = years - 1;
i = i + 1;
}
}
}
Step by step
Solved in 2 steps with 3 images