This is the program specification: Design, write and test a program to display any list of numbers, given the starting number (lower limit), the final number (upper limit) and the step size. Eg. 0,2,4,6,8 (LowerLimit = 0, Upperlimit = 8, StepSize = 2)
I wrote pseudo code for it:
- Set up variables to store the 3 numbers and the loop counter
- Store the lower limit entered by the user
- Store the upper limit entered by the user
- Store the step size entered by the user
- Repeat the following, starting at lower limit, and going up to upper limit in steps of stepsize
- Display the counter
- End of loop
I am struggling to translate step 5 into C# code.
This is what I have done so far:-
class Program { public static Single lowerLimit, upperLimit, stepSizes, counter, upperScaler; static void Main(string[] args) { Console.WriteLine("Enter the lower limit "); lowerLimit = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the upper limit "); upperLimit = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the step sizes "); stepSizes = Convert.ToSingle(Console.ReadLine()); Console.Clear(); for (counter = lowerLimit; counter <= upperScaler; counter++) { Console.WriteLine(counter * stepSizes); if (counter != 1) { upperScaler = upperLimit / stepSizes; } } Console.ReadLine(); } }
Any help will be greatly appreciated.
Comment