Hello everyone. I'm new here and I am still in the beginning stages of learning C#.
I am trying to write a program for school that calculates exponents but I have to use a loop. Then I have to prompt the user if they want to enter some more numbers. If yes, then it should ask if they want to enter the base and power , etc. all over again.
I think I might be close but I keep getting an error in my CalculateTotal method that not all my code paths return a value.
Can someone take a look at what I have and let me know if I am doing this right and what it means by not all my code paths return a value?
Thanks in advance.
using System;
namespace ExponentCalculator
{
class Power
{
static void Main(string[] args)
{
int number = 0;
int power = 0;
int result= 1;
Console.Write("Please enter the base: ");
number = int.Parse(Console.ReadLine());
Console.Write("Please enter the power: ");
power = int.Parse(Console.ReadLine());
CalculateTotal(number, power, result);
CalculationPrompt();
}
public static int CalculateTotal(int number, int power, int result)
{
for(;power != 0; power--)
result*= number;
Console.WriteLine("{0}^{1} = {2}", number, power, result);
}
public static string CalculationPrompt()
{
string moreNumbers;
Console.Write("Would you like to enter another set of numbers (y/n)?");
moreNumbers = Console.ReadLine();
return moreNumbers;
}
}
}