I'm doing a translator from pascal to C and I don't know much of pascal. Would these sentences be a valid sentence in pascal?
while primo and (d<i) do
if (a>5) then
Thanks!!
Yes, it's like while boolean and boolean do ... if ...; after do there must be only one command, because if you want to loop more lines then you can try while ... do begin ... end.
Related
I am working on an English vocabulary learning app. Some of the exercises given to the users are written quizzes. They have to translate French words into English words and vice versa.
To make the checking a little more sophisticated than just "1" or "0" (TypedWord == expectedWord), I have been working with similarities between strings and that worked well (for spelling mistakes for example).
I had also used the contains function, so that for example, if the user adds an article in front of the expected word, it doesn't consider it wrong. (Ex : Ecole (School is expected), but user writes "A school").
So I was checking with lines such as "if (typedWord.contains(word)==true) then...". It works fine for the article problem.
But it prompts another issue :
Ex : A bough --> the expected French word is "branche". If user types "une branche", it considers it correct, which is great. But if user types "débrancher" (to unplug), it considers it correct as well as the word "branche" is a part of "débrancher"...
How could I keep this from happening ? Any idea of other ways to go about it ?
I read the three proposed answers which are really interesting. The thing is that some of the words are compound.... "Ex : kitchen appliance, garden tool" etc... so then I think the "space" functions might be problematic...
In this case, separate the whole answer with the "space", then compare it with the correct word.
For an example:
User's answer: That is my school
Separate it with space, so that you will find an array of words:
that, is, my, school.
Then compare each word with your word. It will give you the correct answer.
The flutter code will be like below:
usersAnswer?.split(" ").forEach((word){
if(word == correctAnswer)
print("this is a correct answer");
});
You can split the string by space and check if the resulting array has the word you're looking for.
typedWord.split(' ').contains('debranche');
So if typedWord is 'une branchethesplit(' ') will turn it into this array: ['une', 'branche'].
Now when you check if this array contains('branche') it will check if the exact string branche exists which in this case it does and returns true.
However if it's 'une debranche' the resulting array would be: ['une', 'debranche'] and because this array has no value equal to 'branche' it will return false. Remember that when you use split it turns the string into an array and by using contains on an array it checks whether or not an item of exactly the value you provide contains exists or not, whereas in a string it checks if part of that string matches the given value or not.
You could check for whitespaces before and after the correct word: something like if (typedWord.contains(' '+word+' ')==true) then..., so that "débrancher" gets marked as wrong. This is kind of strict, though: if the sentence must be completed with some punctuation, it would be rejected by this check. You'll probably want some RegExp that allows punctuation but not whitespaces.
I'm new to this site and this is my first time to ask here.
My problem is I want to check if my string follows a correct pattern or syntax. I'm doing it with C++ String (std::string). I have already done this using C-Style string, however, I want to do it this time in C++ String. Sample problem below:
Input: 2y'' + 3y' - 2y = 0
or y'' = 4y
I want to check if the derivative input is in correct syntax like (a)y'' + (b)y' + (c)y = 0, a second order homogeneous equation. However, I still want to input a non-standard form equation like the second sample input that can be transposed and make it to standard form.
What I did before with it is remove all the white spaces, loop the entire string and check every index. Eg. if 'y' is found the next char should be '\'' or an arithmetic symbol like '-' or '+' or '=' then if it does not match, then, it must return false.
Or maybe I am just implementing this wrong. I'm new to programming and just taking a computer science course. Note: Sorry for my bad English and sorry if I did not written my code here. Its just way too long.
Regular expressions might be the answer. They're commonly used for checking whether a string first a format, or finding parts of a string that do.
RegExr is a great tool to both learn and test your regular expressions.
I need to read a String character by character. i.e, If I have a string like CILD, then I have to read it as C and then I and so on.
I tried this with regex and also with properties, but nothing has worked out.
Please let me know a solution for the same.
thanks.
You can use the below snippet in your code to add a _ at end of every character
propertyregex property="propB" input="${input}" regexp="" replace="_" global="true"
And then split the property with dleimiter as "_".
for list="${propB}" delimiter="_" param="split"
Cheers.
Note : This worked out very well for me.
I am going through some examples in a book I have and I have come to something I've never seen before nor understand:
scanf("%d-%d-%d-%d-%d", &prefix, &group, &publisher, &item, &check_digit);
This code is part of a program that asks the user to enter their ISBN number of a book and later on breaks down the ISBN into Prefix = x, Group = y, etc..
I have NEVER seen the hypens between the %d's. Does anyone see any point in this??
Thanks
"Pattern matching". If the input doesn't fit the specified pattern (also called format), it fails. So if you input anything else than INT-INT-INT-INT-INT (where INT is a placeholder for an integer you input), the input would be considered invalid.
The represent the actual parts of the string to be scanned.
For example your "%d-%d-%d-%d-%d" would work with something like "10-56-666-1-90".
It parses 5 numbers (matched by %d) with a dash between each two (the -). Each number is saved to a variable passed in as argument. See the manual for scanf and printf under Conversions.
scanf takes a format string, so it's about what input it expects to see for input. The hyphens are for actual hyphens in the input. 1-2-3-4-5-6 would be valid input for this call, and give you prefix=1, group=2, etc.
I'm programming a program in C++ (typical game) in which you need to guess a letter and it will check if it is present in a string.
For example
Secret String: I like to program.
Guess1: 'a'
Display: . .... .. .....a...
Etc.
But i don't know how to see if a character is in this secret string.
I'm using std::string (obligatory)
Any help is appreciated!
Begin by learning searching in a documentation like : http://www.cplusplus.com/reference/string/string/ . (Hint : you want to "find" something ... )
You can use find_first_of
There are several methods in std::string that would help:
find()
rfind()
find_first_of()
find_last_of()
substr()
Take a look at string::find