Sinisterly
made a program - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: made a program (/Thread-made-a-program)

Pages: 1 2 3


made a program - 13295 - 09-01-2011

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????


RE: made a program - chipp - 09-02-2011

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


RE: made a program - Jacob - 09-02-2011

compiles properly, but hsa an error and closes when typing more than about 12 letters



RE: made a program - 13295 - 09-02-2011

(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..


RE: made a program - Jacob - 09-02-2011

im using micorsoft visual c++ 2010 built in compiler. has no errors


RE: made a program - 13295 - 09-02-2011

maybe it's different i use code::blocks mingw. you can download it, click Download it here in the first post.


RE: made a program - Jacob - 09-02-2011

i have no errors at all, so that means the compilers are inter-compatible.


RE: made a program - 13295 - 09-02-2011

(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?


RE: made a program - Jacob - 09-02-2011

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


RE: made a program - 13295 - 09-02-2011

What's your OS?

Do you have winxp??