Oli R.
Oli R.
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
inside the for-loop comes a if statement which ask if there is a "-" inside the userInput like: if(userInput[i] != "-"){ ... }
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
before the for-loop declare a variable which counts the hyphen inside the userInput: int hyphenCounter = 0;
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
You can also do user Input.IndexOf('-') or user Input.LastIndexOf('-') to see if and where there is a '-' inside the user-input-string. But the easiest way would be to iterate over the user-input-string with a for-loop to check if the actual character is a "-". excample: for( int i = 0; i < userInput.Length; i++) { ... }
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
After that define one variable for the user-string-input like: string userInput = Console.ReadLine();
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
Until this it's okay: using System; public class Program { static void Main(string[] args) { Console.WriteLine("Bitte geben sie bitte ein Wort-Wort-Zahl ein");
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
Your point.
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
But when the first or second String could also parsed into a Integer the Error Message has to be displayed too.
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
Well, in my opinion, it can be very difficult for a beginner to come up with good English names for the identifiers in addition to learning a new programming language, especially if he is not a native English speaker.
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
The easiest way would be to check each letter of the string within a loop to see if it isn't a "-" and append it to a new string. Do the same with a 2nd new string to the 2nd “-” and a 3rd new string to the end of the whole string. Now all you have to do is check which of the three strings you can parse into an integer and finally output the corresponding message.
38 replies
CC#
Created by j7nooah on 11/15/2023 in #help
I am new to c# and need help
There you can look up all the string-methods (in german) for the task: https://learn.microsoft.com/de-de/dotnet/api/system.string?view=net-7.0#methods I would consider Compare() as a possible candidate, but a few properties are quite interesting too. You can also loop through the string to check whether the character "-" is included twice and whether the last string can be parsed into an integer.
38 replies