vowel removal challange...what is it thats not working

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1932 Views - Last Post: 09 October 2012 - 05:13 AM Rate Topic: -----

#1 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

vowel removal challange...what is it thats not working

Posted 08 October 2012 - 07:35 AM

im supposed to do this using c_string, pulling out each chatacter and checking it, i figured it would be easier this way and then sussed out c_string but it doesn't work, i havnt completley sussed out errase and how to use an array of chars and find the length (size of?)i havnt played with vectors yet either, im very much the beginner and i appreciate the kind of help that gives one hints over the answer but that can be hard to do...thanks for checking this out guys =)


#include <iostream>
#include <string>


using namespace std;

int main ()
{


string stringone;
cout << "put in the stinking sentence mofo" << endl;
getline (cin,stringone);
string string1;

string1.assign(stringone);

for (int q=0;q > stringone.length();q++)
{
 switch (stringone[q])
    {
        case 'a':
        string1.replace(q,q+1," ");
        break;
        case 'e':
        string1.replace(q,q+1," ");
        break;
        case 'i':
        string1.replace(q,q+1," ");
        break;
        case 'o':
        string1.replace(q,q+1," ");
        break;
        case 'u':
        string1.replace(q,q+1," ");
        break;

    }

}
cout << stringone << " is " << string1 << endl;

return 0;
}



ah yeah i messed with erase and a few other string functions, im just trying to remove the vowels in any way at the moment after this have you got anygood ideas to practice??

Is This A Good Question/Topic? 0
  • +

Replies To: vowel removal challange...what is it thats not working

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 07:42 AM

Instead of using string.repalce, why don't you just replace the character?
string1[q] = ' ';


Also you don't really need to use the assign() function with std::strings you could just use the assignment operator=.
string1 = string2;


Jim
Was This Post Helpful? 0
  • +
  • -

#3 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 08:26 AM

no this still dont work, the unusual way about somethings is me testing them out
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 08:28 AM

Post the modified code. Just saying it doesn't work doesn't tell us anything.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 08:29 AM

It might help us if you provide to us what is so unusual about the way you test it :
Doesn't work isn't good enough
Was This Post Helpful? 1
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 08:40 AM

You may also want to look closely at your for statement:
for (int q=0;q > stringone.length();q++)

Pay very close attention to the condition clause (q > stringone.length()). When will q be larger than the length of your string?

Jim
Was This Post Helpful? 0
  • +
  • -

#7 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 10:35 AM

you dont need to know the code you jsut need to know it doesnt work as for the <> deal thats the only ything i changed and its wrond cos i been a fiddlin wiv it, you run it it no workee

is it the settings on my commiler maybe?
Was This Post Helpful? -8
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 10:40 AM

No it is not the settings on your compiler, it's your program.

And we do need to see your code, without seeing the modified code we can't help you further.

Jim
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 10:46 AM

View Postdevonrevenge, on 08 October 2012 - 11:26 AM, said:

no this still dont work

...

View Postdevonrevenge, on 08 October 2012 - 01:35 PM, said:

you dont need to know the code

If you are going to ask for help here, you need to understand & respect the fact that questions being asked (although you may not understand) are being asked for a reason. We're not going to be able to properly troubelshoot your code without your assistance. Description alone doesn't tell us 100% of what's wrong, & just because you perceive it one way doesn't mean that's the issue.

Please be mindful of those experienced in the languages you are asking for help with.
Was This Post Helpful? 1
  • +
  • -

#10 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 01:45 PM

okay its identical to the one you have only < is now > that is all so you have my code i wasnt being feacicious its right there bam

the code is at the top its not any different like i said
Was This Post Helpful? -2
  • +
  • -

#11 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 282
  • Posts: 1,491
  • Joined: 07-April 08

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 02:05 PM

Have you taken jimblumberg advice in Post 6. You need to look closely at your for loop, and ask yourself the question when will q be greater then the length of your char array.

Maybe this will help:

set q equal to 0; loop while q is greater then stringone.length(); increment q by one with every loop.

This post has been edited by rgfirefly24: 08 October 2012 - 02:10 PM

Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3622
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 02:27 PM

You still didn't tell us what is not working. What inputs are you giving, what output are you seeing, and what output were you expecting to see?

Just glancing at your code, and assuming you just changed the greater than to a less than comparison on line 18, then the next thing that looks very wrong are these lines:
string1.replace(q,q+1," ");


Parameter 2 is the number of characters to be replaced. So that line of code says: starting at the q-th element, replace q+1 elements with the string " ". All you want to do is just replace a single character, not q+1 characters.
Was This Post Helpful? 2
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: vowel removal challange...what is it thats not working

Posted 08 October 2012 - 02:31 PM

If you don't want any help your answers are really helping. If however you do desire help then it is imperative that you provide the information requested. You have been given several suggestions and as far as I can see you haven't even tried any of these suggestions. So post your code and explain why the suggestion didn't help. You do this by showing what you have inputted into the program and showing the output the program is producing, if the program compiles. If it doesn't compile then provide the complete error messages exactly as they appear in your development environment. When you describe why the suggestions didn't work try to explain the reasons in proper English.

Jim
Was This Post Helpful? 0
  • +
  • -

#14 devonrevenge  Icon User is offline

  • New D.I.C Head

Reputation: -10
  • View blog
  • Posts: 22
  • Joined: 08-October 12

Re: vowel removal challange...what is it thats not working

Posted 09 October 2012 - 01:48 AM

:cry2: you guys are so mean and free with your demoralizing bad reputation points...

kay here goes anyways, it compiles just i get the error message 'program ended in an unusual way' and thas it.

i also set the arrow to the other side and tried a whole load of deleting/replacing and erasing commands, i dont believe it could be the only flaw in the code but then im a complete novice worst than that im a complete novice with a bad reputation





#include <iostream>
#include <string>


using namespace std;

int main ()
{


string stringone;
cout << "put in the stinking sentence mofo" << endl;
getline (cin,stringone);
string string1;

string1 = stringone;

for (int q=0;q < stringone.length();q++)
{
 switch (stringone[q])
    {




       case 'a':

        string1.erase (q);

        break;

        case 'e':

        string1.erase(q);

        break;

        case 'i':

        string1.erase(q);

        break;

        case 'o':

        string1.erase(q);

        break;

        case 'u':

        string1.erase (q);

        break;




    }

}
cout << stringone << " is " << string1 << endl;

return 0;
}



















....i only didnt want to copy and paste cos all the bloody numbers up the side have to be deleted...its not like i could ask you guys to ignore them without getting exiled now is it...now i have to learn to program with the albatross of a bad reputation hanging round my neck, you guys will look down on me forever from your ivory towers of programming knowledge and experience why not even my mother looks at me in the same way anymore...and my dad, he says he still loves me like the son he never had...whats that even mean?

thanks guys way to encourage a noob
Was This Post Helpful? 0
  • +
  • -

#15 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5882
  • View blog
  • Posts: 12,761
  • Joined: 16-October 07

Re: vowel removal challange...what is it thats not working

Posted 09 October 2012 - 04:03 AM

Strangely, you didn't really follow the advise of this lot, either: http://www.cplusplus...beginner/81168/

Everyone is mean? It depends on your perspective. We're here to help people who want to learn. This usually involves gentle prods and encouragement, but hard cases sometimes require more than a prod to get them going. What's really mean is just giving someone the answer, because then they learn nothing and the next assignment will be than much harder.

Also note that erase probably doesn't behave the way you think it does. Once you've removed your character and shortened your string by one, you might what to reconsider always moving q forward.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2