Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


made a program filter_list
Author
Message
made a program #1
Hello i have coded a program in C++. the program based on Tri Code from wikihow, so Download it here and try it. or if you got a compiler this is the code

Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{

    string texts; // regular texts
    string output; // converted texts
    cout << "Type some texts: ";
    getline(cin,texts); // user input the text
    while(int i = texts.length()) //
    {
        texts[i+1]=' ';
        texts[i+2]=' ';
        texts[i+3]=' ';
        break;
    }
    for (int i=0;i<=texts.length();i++) // Removing Spaces
    {
        if (texts[i]==' ')
        {
            for (int g = i;g<=texts.length();g++)
            texts[g]=texts[g+1];
        }
    }
    for (int i=0;i<=(texts.length());i+=3) // Convertings
    {
        output[i]=texts[i+2];
        output[i+1]=texts[i+1];
        output[i+2]=texts[i];
    }
    cout << endl;
    cout << "Output text: ";
    for (int i=0;i<=texts.length();i+=3) // Output the converted texts with a space every 3 characters
    {
        cout<<output[i];
        cout<<output[i+1];
        cout<<output[i+2];
        cout<<" ";
    }
    cout<< endl;
    cout<< endl;
    cout<<"Press any key";
    cin.get();

    return 0;
}

what do you think????
(This post was last modified: 09-02-2011, 11:22 AM by Azade.)
[Image: dd.png]

Reply

RE: made a program #2
i don't know what are you're tryna do, but, i would change it to something like this:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{

    string texts;
    string output;
    cout << "Type some texts: ";
    getline(cin,texts);
    while((int i = 0, i <= texts.length()) // <-----------
    {
        texts[i+1]=' ';
        texts[i+2]=' ';
        texts[i+3]=' ';
        break;
    }
    int count = 0;
    for (int i=0;i<=texts.length();i++)
    {
        // *** from here ***

        if (texts[i]==' ')
                continue;
        texts [count] = texts [i];
        count += 1;

        // *** to here ***

    }
    for (int i=0;i<=(texts.length());i+=3)
    {
        output[i]=texts[i+2];
        output[i+1]=texts[i+1];
        output[i+2]=texts[i];
    }
    cout << endl;
    cout << "Output text: ";
    for (int i=0;i<=texts.length();i+=3)
    {
        cout<<output[i];
        cout<<output[i+1];
        cout<<output[i+2];
        cout<<" ";
    }
    cout<< endl;
    cout<< endl;
    cout<<"Press any key";
    cin.get();

    return 0;
}

look at the comments. i suppose what you want is:

Code:
int i = 0;
while (i <= texts.length())
and for skipping the spaces i think you should use continue except that there's only 1 space every time space is found...

CMIIW
[Image: ap8g35.jpg]

Reply

RE: made a program #3
compiles properly, but hsa an error and closes when typing more than about 12 letters

Reply

RE: made a program #4
(09-02-2011, 06:15 AM)chipp Wrote: i don't know what are you're tryna do, but, i would change it to something like this:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{

    string texts;
    string output;
    cout << "Type some texts: ";
    getline(cin,texts);
    while((int i = 0, i <= texts.length()) // <-----------
    {
        texts[i+1]=' ';
        texts[i+2]=' ';
        texts[i+3]=' ';
        break;
    }
    int count = 0;
    for (int i=0;i<=texts.length();i++)
    {
        // *** from here ***

        if (texts[i]==' ')
                continue;
        texts [count] = texts [i];
        count += 1;

        // *** to here ***

    }
    for (int i=0;i<=(texts.length());i+=3)
    {
        output[i]=texts[i+2];
        output[i+1]=texts[i+1];
        output[i+2]=texts[i];
    }
    cout << endl;
    cout << "Output text: ";
    for (int i=0;i<=texts.length();i+=3)
    {
        cout<<output[i];
        cout<<output[i+1];
        cout<<output[i+2];
        cout<<" ";
    }
    cout<< endl;
    cout<< endl;
    cout<<"Press any key";
    cin.get();

    return 0;
}

look at the comments. i suppose what you want is:

Code:
int i = 0;
while (i <= texts.length())
and for skipping the spaces i think you should use continue except that there's only 1 space every time space is found...

CMIIW

Thank but is there different between mine and yours? i think it is more faster? i am a beginner.
(09-02-2011, 06:22 AM)Jacob Wrote: compiles properly, but hsa an error and closes when typing more than about 12 letters

There might be something wrong with your compiler..
(This post was last modified: 09-02-2011, 07:48 AM by Azade.)
[Image: dd.png]

Reply

RE: made a program #5
im using micorsoft visual c++ 2010 built in compiler. has no errors

Reply

RE: made a program #6
maybe it's different i use code::blocks mingw. you can download it, click Download it here in the first post.
[Image: dd.png]

Reply

RE: made a program #7
i have no errors at all, so that means the compilers are inter-compatible.

Reply

RE: made a program #8
(09-02-2011, 08:21 AM)Jacob Wrote: i have no errors at all, so that means the compilers are inter-compatible.

You said it has error, what does the error say?
(This post was last modified: 09-02-2011, 08:24 AM by Azade.)
[Image: dd.png]

Reply

RE: made a program #9
i have no error compiling, just when i try to enter a lot, it has the generic, has crashed and needs to close, send error report?


i compiled using cl /EHsc program.cpp

WOOO Biggrin
post 700 :epic:



ERRORR BiggrinD

Reply

RE: made a program #10
What's your OS?

Do you have winxp??
[Image: dd.png]

Reply







Users browsing this thread: 1 Guest(s)