Guys I hope you are all doing well.
Im trying to build a program for some children to Learn how to write the word Banana.
The program should give output yes if the input is banana and no if the input is not banana.
Another thing is that it should ignore the repeated letters like bbbbaanaanaa should be considered as a yes.
And Bannaann should be considered as no because there's a missing "a" at the end.
I'm working on the code I'll submit later but if anyone has an idea please help.
THANKS IN ADVANCE
Well this seems like a worthwhile function to write.
1 2 3 4 5 6 7 8 9
string removeRepeatedLetters(string word) {
// put some code here
}
int main ( ) {
string test = "bbbbaanaanaa";
string result = removeRepeatedLetters(test);
cout << test << "=>" << result << endl;
}
No user interface, no Q&A from the users, no "yes or no" was it right.
Just focus on making a function do one specific thing, and do it well.
When it works, then you can start to add more stuff to main.
#include <iostream>
#include <string>
std::string remove_repeated_letters(std::string word)
{
/*Put things in here*/
}
int main ( )
{
std::string input;
std::cout << " Enter word to test : ";
std::cin >> input;
std::string result = remove_repeated_letters(input);
std::cout << " Your word without repeated letters is : " << result
<< "\n Is your word \"banana\"?" << "\tThe answer is : ";
if (result == "banana") std::cout << "Yes";
else std::cout << "No";
}
Output:
Enter word to test : bbbbbbbbbbbaaaaaannnnnnnnaaaaaaaana
Your word without repeated letters is : banana
Is your word "banana"? The answer is : Yes
Enter word to test : pinnnnneappplllle
Your word without repeated letters is : pineaple
Is your word "banana"? The answer is : No
to help you out a bit here's how I would make the pseudocode:
>create a char array and initialise its content to the string you're passing to the function
>create an empty string to hold the word with no repeating letters
>for each char of the array, starting at the second char until the end of the array is reached.
>>if the previous char is different from current char, append previous char to new string
>>else do nothing
>return new string
EDIT: you could also mess with capital chars to put everything to lowercase but I don't think you're looking for that so far
The instructions are very hard to me because English is not my born language if possible can u instruct me by using comments in the code. I would really appreciate that. Thanks
An alternative is you write the comments in your language and we'll translate them to see if you understand the code. That way you're sharing the workload. BTW, your English isn't too bad at all.
The instructions are very hard to me because English is not my born language if possible can u instruct me by using comments in the code. I would really appreciate that. Thanks
What is your native language? and what do you need comments on, do you mean you want me to explain that:
>create a char array and initialise its content to the string you're passing to the function
>create an empty string to hold the word with no repeating letters
>for each char of the array, starting at the second char until the end of the array is reached.
>>if the previous char is different from current char, append previous char to new string
>>else do nothing
>return new string
> एक चार सरणी बनाएं और अपनी सामग्री को उस स्ट्रिंग पर इनिशियलाइज़ करें जो आप फ़ंक्शन में पास कर रहे हैं
> कोई दोहराए जाने वाले अक्षरों के साथ शब्द को पकड़ने के लिए एक खाली स्ट्रिंग बनाएं
> सरणी के प्रत्येक चार के लिए, सरणी के अंत तक दूसरे चार्ट पर शुरू करना।
>> यदि पिछला चार्ट वर्तमान चार्ज से अलग है, तो पिछले चार को नए स्ट्रिंग में जोड़ें
>> और कुछ नहीं करते
> नई स्ट्रिंग लौटाएं
Or,
> eagar cairr a chruthú agus a ábhar a thúsú leis an teaghrán a bhfuil tú ag gabháil dó don fheidhm
> cruthaigh teaghrán folamh chun an focal a choinneáil gan aon litreacha athrá a dhéanamh
> i gcás gach cairr den eagar, ag tosú ag an dara ruaig go dtí go sroichtear deireadh an eagar.
>> má tá an t-charr roimhe seo difriúil ó charr atá ann faoi láthair, cuir an t-eireaball le sreangán nua
ní dhéanann aon rud eile
> seol teaghrán nua ar ais
Well I think it's okay and it's probably the same as other languages when it comes to learning programming languages. It was the same for me. You just need to get used to the English words and vocab to deal with C++, for instance here, you need to know what the following things are:
>a function
>to initialise, create
>an array
>a character
>a string
>to return
>to assign, add, append to
>if / else
But this vocabulary should be explained in detail with whatever you're learning with.
Are you taking classes or are you learning from a textbook?
Maybe you have a neighbour who can help out with this as a go between language:
> tengeneza safu ya chati na uanzishe yaliyomo katika tambo unayopita kwenye kazi
> tengeneza kamba tupu kushikilia neno bila barua zinazorudia
> kwa kila chati ya safu, kuanzia saa ya pili hadi mwisho wa safu hiyo imefikiwa.
>> ikiwa chati ya zamani ni tofauti na chati ya sasa, ongeza chati ya zamani hadi kamba mpya
>> kingine usifanye chochote
> rudisha kamba mpya
@H00G0 I'm not taking any classes I'm just learning through books and other resources on the internet. But with examples I understand more.
Like taking a program coded by someone and try to understand it.
That is how i Learn c++
Like taking a program coded by someone and try to understand it.
Many people, including myself, will tell you that the best way of learning is doing it yourself. Start with the simplest and work your way up. understanding others' code is great, but that doesn't mean you can write yours on your own.
If this task is too difficult for you, pick an easier one and come back to it later. I can provide the code for your function, but if you don't make it yourself you're not really learning anything :)
I would really appreciate the the function code. I know it's not the best way of learning but I'm trying my level best to understand c++ without additional help from a teacher.
Thanks in advance