Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace random
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isCorrect = false;
- //loop to repeat if user input cannot be parsed
- do
- {
- Console.Write("Please enter a number: ");
- string userInput = Console.ReadLine();
- //try catch block to test if user input is correct
- //if it is it writes result to Console
- try
- {
- int resultAsInt = int.Parse(userInput);
- Console.WriteLine("\nThe cubed value of {0} is {1}.", resultAsInt, resultAsInt * resultAsInt * resultAsInt);
- isCorrect = true;
- }
- catch
- {
- Console.WriteLine("Not able to parse. User entered {0}", userInput);
- }
- } while (!isCorrect); //Check to see if input is correct and whether or not to keep looping.
- Console.WriteLine("\nProcess Finished");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement