Beginner to C# here coding a calculator using a compiler on my phone and need some help please

As the title says im a beginner to C# and am making a calculator using a compiler on my phone, I doubt I’ve done it the most effective or efficient way but I’m proud of what I have so far using what I’ve learned so far. The problems I’m having trouble solving are:

1) I have it so that if the user doesn’t enter anything from the array then it would run console.readline() continuously until the user enters something from the array, while it will continuously prompt new input from the user if the user puts in something from the array at this point it doesn’t recognize and run the corresponding function for that array anymore.

2) I have a string that the console prints out after using the multiply array asking wether the user would like to repeat that function so they could do another multiplication after already doing it once, I have tried several ways but I’m struggling to figure out how to repeat the entire array function again when the user says yes and return to the first string that asks which function the user wants to perform if they say no.

Heres the coding, any help would be really appreciated thanks.

Edit: sorry for the cluster layout of the code, I copied and pasted it from the compiler but it looks different and much more tidy within the compiler.

public static void Main() { string[] userInput = {“×”, “+”, “-“, “÷”}; string symbolInput; string Repeat = “Would you like to use the same function again? Enter (Y) for yes or (N) for no.”; string Answer; int X; int Y; bool Valid = true;

 Console.WriteLine(" Please enter one of these symbols and hit enter to start: +, ×, ÷, -"); symbolInput = Console.ReadLine(); if (symbolInput == userInput[0]) { Valid = true; Console.WriteLine("Please enter the two numbers you want to multiply below and hit enter after each number"); X = Convert.ToInt32(Console.ReadLine()); Y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(X * Y); Console.WriteLine(Repeat); Answer = Console.ReadLine(); } else if (symbolInput == userInput[1]) { Valid = true; Console.WriteLine("Please enter the two numbers you wish to add below and hit enter after each number"); X = Convert.ToInt32(Console.ReadLine()); Y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(X + Y); } else if (symbolInput == userInput[2]) { Valid = true; Console.WriteLine("Please enter the two numbers you want to subtract and hit enter after each number"); X = Convert.ToInt32(Console.ReadLine()); Y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(X - Y); } else if (symbolInput == userInput[3]) { Valid = true; Console.WriteLine("Please enter the two numbers you want to divide and hit enter after each number"); X = Convert.ToInt32(Console.ReadLine()); Y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(X/Y); } else { Valid = false; while (Valid == false) Console.ReadLine(); if (symbolInput == userInput[0]) { Valid = true; } } } 

submitted by /u/Alevel8FlipFlop
[link] [comments]

Leave a Reply