Reputation: 137
I am trying to make a simple interest calculator wherein a person enters a number (1 - 4) for what they want to calculate, then enter the given numbers and get the missing variable.
code:
using System;
using System.Convert;
public class InterestCalculator {
static public void Main(string [] args) {
int final, initial, rate, time, input;
Console.WriteLine("What do you want to calculate? \n 1. Final amount after interest. \n 2. Initial amount after interest. \n 3. Interest rate. \n 4. Time passed");
input = Convert.ToInt32(Console.ReadLine());
switch (input){
case 1:
Console.WriteLine("Enter the initial amount.");
initial = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the interest rate.");
rate = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the time passed.");
time = Convert.ToInt32(Console.ReadLine());
final = initial * rate * time;
Console.WriteLine("$" + final + " is the final amount after interest.");
break;
case 2:
Console.WriteLine("Enter the final amount.");
final = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the interest rate.");
rate = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the time passed.");
time = Convert.ToInt32(Console.ReadLine);
initial = final/(rate * time);
Console.WriteLine("$" + initial + " is the initial amount before interest.");
break;
case 3:
Console.WriteLine("Enter the final amount.");
final = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the initial amount.");
initial = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the time passed.");
time = Convert.ToInt32(Console.ReadLine);
rate = final/(initial * time);
Console.WriteLine("%" + initial + " per time cycle is the interest rate");
break;
case 4:
Console.WriteLine("Enter the final amount.");
final = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the initial amount.");
initial = Convert.ToInt32(Console.ReadLine);
Console.WriteLine("Enter the interest rate.");
rate = Convert.ToInt32(Console.ReadLine());
time = final/(initial * rate);
Console.WriteLine(initial + " cycles is the amount of time passed.");
break;}
default:
Console.WriteLine("Invalid input.");
}
}
}
I keep getting this error in the compilation process (using mono):
error CS1502: The best overloaded method match for System.Convert.ToInt32(bool) has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'
error CS1502: The best overloaded method match for `System.Convert.ToInt32(bool)' has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'
error CS1502: The best overloaded method match for `System.Convert.ToInt32(bool)' has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `bool'
Upvotes: 0
Views: 431
Reputation: 890
Most of the places you only have
Console.ReadLine instead of Console.ReadLine()
Check in code. For example -
Case 2
time = Convert.ToInt32(Console.ReadLine);
Correct all these lines.
Also, suggested to get input first into local variable and then try to convert.
Upvotes: 0
Reputation: 6531
Well one of your Console.ReadLine()
doesn't have brackets. So you're passing the method rather than calling it.
Upvotes: 4