+ 6

"CHALLENGE" : Code a program which accepts infinite input errors and exceptions and loops and states the error too.

Code a program which can handle infinite input errors and loops itself until the correct input/type of input. Eg: A calculator which when given string as input, describe the error but doesn't terminate and loops until the correct type of input is provided.

6th Dec 2017, 4:05 PM
Ritwek Jaiswal
5 Respostas
+ 18
Intresting challenge 😊 Something like this: https://code.sololearn.com/cC6GHcx410il/?ref=app
6th Dec 2017, 6:49 PM
LukArToDo
LukArToDo - avatar
+ 2
while(1) { cin>>input; if(input==Ok) break; }
6th Dec 2017, 5:30 PM
ehsan safamanesh
ehsan safamanesh - avatar
+ 1
So should it terminate after getting the correct answer or just keep running even after that .
6th Dec 2017, 4:49 PM
RZK 022
RZK 022 - avatar
+ 1
According to ur wish but loop even after correct input would be an interesting game!
6th Dec 2017, 5:27 PM
Ritwek Jaiswal
0
using System; class Program { public static double RandomDouble(double min, double max) { Random random = new Random(); return random.NextDouble() * (maximum - minimum) + minimum; } public static double Sigmoid(double x) { //return 1 / (1+e^-x) return 1 / (1 + Math.Exp(-x)); } double input, weight1, weight2, hiddenNeuron1, hiddenNeuron2, weight3, weight4, output1; double biasWeight1, biasWeight2, biasWeight3; //Assuming the bias value is +1.00 int trials = 0; static void ForwardPropogate() { trials++; if(trials == 0) { weight1 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); weight2 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); weight3 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); weight4 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); biasWeight1 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); biasWeight2 = RandomDouble(-1, 1); System.Threading.Thread.Sleep(50); weight3 = RandomDouble(-1, 1); hiddenNeuron1 = Sigmoid((input1 * weight1) * biasWeight1); hiddenNeuron2 = Sigmoid((input2 * weight2) * biasWeight2); output1 = Sigmoid(((hiddenNeuron1 * weight3) + (hiddenNeuron2 * weight4) * biasWeight3); Console.WriteLine(“output1” + output1); Console.ReadKey(); } else { } } static void BackwardPropogate() { //This section contains calculus and gradient descent so it will not be included } } //Yes, I know I should use arrays to make the code neater and shorter but without them it is easier to understand. //This neural network is a 1 2 1 network (which means it has 1 input neuron, 2 hidden neurons and 1 output neuron. These are kept in different layers called the input layer, the hidden layer and the output layer. //To calculate a hidden neuron, all we need to do is h1 = Sig(i1 * w1) and h2 = Sig(i2 * w2). And to calculate the output neuron, we need to do o1 = Sig((h1 * w3) + (h2 * w4)) //This method is called forward propagation and it is only half of the neural network. I just realised how hard it actually is to write code on an iPhone
7th Dec 2017, 10:13 PM
Killer POTA
Killer POTA - avatar