Hi!
I need to write a program that moves some letters to the end of a word for example if i enter : cook look book telephone, the result would be: ookc ookl ookb elephonet.
i came up with some code but then my ideas run aout...some help would be appreciated =)

My code so far:

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string txt;
{
cout <<"Enter string"<<endl;
getline(cin,txt);
}
for (int i=0; i<int(txt.size()); ++i)
{
if (txt[i]=='a' || txt[i]=='e' || txt[i]=='i' || txt[i]=='o' || txt[i]=='u')
cout<<txt[i];
}
for (int j=0; j<int(txt.size()); ++j)
{
if (txt[j]=='q' || txt[j]=='w' || txt[j]=='r' || txt[j]=='t' || txt[j]=='y' || txt[j]=='p'
|| txt[j]=='s' || txt[j]=='d' || txt[j]=='f' || txt[j]=='g' || txt[j]=='h' || txt[j]=='j'
|| txt[j]=='k' || txt[j]=='l' || txt[j]=='z' || txt[j]=='x' || txt[j]=='c' || txt[j]=='v'
|| txt[j]=='b' || txt[j]=='n' || txt[j]=='m')
cout<<txt[j];
}
getch();
return 0;
}

Recommended Answers

All 3 Replies

Not sure why you have such a long for loop at the end there.
Surely you can make the string into a list of chars, then you add a character at the end (which is the same as the first one) and remove the starting character.

Sorry, i dont get it XD
Some sample code or more detailed explanation?

Id be grateful :)

Say you have a string: [potato]
You convert the word into a list of chars: [p] [o] [t] [a] [t] [o]
You clone the first letter and place it at the end: [p] [o] [t] [a] [t] [o] [p]
You remove the first letter: [o] [t] [a] [t] [o] [p]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.