+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
Coding Thread, Help quickly in Coding and Web Development; I want to have a program, where I input a 6 digit number, it does a sum to the 6 ...
  1. #1

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443

    Help quickly

    I want to have a program, where I input a 6 digit number, it does a sum to the 6 digit number, then, takes the various digits, and output the nearest whole number (rounded down), then puts the digits in a certain order (EG last 2, first 2, middle 2)

    So it would do for argument sake (135791 + 123123)/3 = 086394 OUTPUT 940863

    I am time short on this one, and wondered if someone could lend a hand?

    Ideally in C++

    I will post up later when home my code to date, but as I am at work, it is a bit difficult to do so.

  2. #2

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    182
    I don't know about C++ but I can do it quite easy in PowerShell

    Code:
    Get-Random

  3. Thanks to Ric_ from:

    nephilim (26th March 2013)

  4. #3

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443
    HA!

    No it is for the company I work for. They are using excel right now to run the calculations etc, but agreed it would be easier to have a program whipped up and done. However I can't seem to get the last bit done where it pulls the digits in groups of 2

  5. #4

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,528
    Thank Post
    1,460
    Thanked 1,214 Times in 823 Posts
    Rep Power
    724
    Quote Originally Posted by nephilim View Post
    HA!

    No it is for the company I work for. They are using excel right now to run the calculations etc, but agreed it would be easier to have a program whipped up and done. However I can't seem to get the last bit done where it pulls the digits in groups of 2
    Convert the number to a string?

    Converting numbers to strings and string - C++ Articles

  6. #5

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443
    Thats fine, but how would I do it then if it registers as a 5 digit number, as it needs to be 6 (with a 0 at the front).

  7. #6

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,528
    Thank Post
    1,460
    Thanked 1,214 Times in 823 Posts
    Rep Power
    724
    OK just had a play, here's a very basic program which should demonstrate how to do this. there is no error checking, just standard IO to console, but you should be able to adapt it to your needs:

    Code:
    #include <iostream>
    #include <sstream>
    
    using namespace std;
    
    int main()
    {
        int iStart;
        int iCalculated;
        string sResult;
        ostringstream convert;
    
        cout << "Enter a 6 digit number: ";
        cin >> iStart;
    
        //perform calculations
        iCalculated = (iStart + 135791) / 3;
        cout << "(" << iStart << " + 135791) / 3 = " << iCalculated << "\n";
    
        //convert result to string
        convert << iCalculated;
        sResult = convert.str();
    
        //prepend with 0's if neccessary
        if (sResult.length() < 6)
        {
            string sZeroes;
            sZeroes.append(6 - sResult.length(), '0');
            sResult = sZeroes.append(sResult);
        }
    
        cout << "String converted and length fixed: " << sResult << "\n";
    
        //rearrange string
        cout << "Re-arranged string: "<< sResult.substr(4,2) << sResult.substr(0,2) << sResult.substr(2,2);
        return 0;
    }
    And an exe if you want to see a demo: https://dl.dropbox.com/u/4779199/Nep...r%20Crunch.zip

  8. #7

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443
    Looks good, however it shuts down at the end, before the end number is generated

  9. #8

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,528
    Thank Post
    1,460
    Thanked 1,214 Times in 823 Posts
    Rep Power
    724
    Quote Originally Posted by nephilim View Post
    Looks good, however it shuts down at the end, before the end number is generated
    The end number is simply that last cout that pulls the number pairs out as substrings and prints it to console. If you want that number actually stored (as a string, otherwise you won't have your preceding zeroes, you could change the last part from:

    Code:
    //rearrange string
        cout << "Re-arranged string: "<< sResult.substr(4,2) << sResult.substr(0,2) << sResult.substr(2,2);
    To:

    Code:
    //rearrange string
        sResult = sResult.substr(4,2) + sResult.substr(0,2) + sResult.substr(2,2);
        cout << "Re-arranged string: "<< sResult;
    Really, how you deal with the final result will depend what it is you actually want to do with it. Will this code be added to an existing C++ program? If so, whack it in a function. If not, you'll have to adapt it to take an integer as a CLI argument then output the result to a file or something where you can read it... happy to help with any of that, just need more specifics

    EDIT: obviously you wouldn't need all the 'cout' everywhere in the final program, I just put those there to make it obvious how it works
    Last edited by LosOjos; 26th March 2013 at 02:02 PM.

  10. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,848
    Thank Post
    3,363
    Thanked 1,062 Times in 982 Posts
    Rep Power
    366
    Does it have to be in C++ or could you not do a HTA in vbscript or use dot net based IDE ie vb.net or c#.net etc ??

  11. #10

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443
    C++ would be preferred. Now to compile it. Any good compilers that are light?

  12. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,848
    Thank Post
    3,363
    Thanked 1,062 Times in 982 Posts
    Rep Power
    366

  13. #12

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,528
    Thank Post
    1,460
    Thanked 1,214 Times in 823 Posts
    Rep Power
    724
    Personally I use CodeBlocks as a nice simple IDE, but if you simply want a compiler then MinGW is popular (assuming you're on a Windows machine)

  14. Thanks to LosOjos from:

    mac_shinobi (26th March 2013)

  15. #13

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,179
    Thank Post
    1,648
    Thanked 1,973 Times in 1,445 Posts
    Blog Entries
    2
    Rep Power
    443
    Quote Originally Posted by LosOjos View Post
    Personally I use CodeBlocks as a nice simple IDE, but if you simply want a compiler then MinGW is popular (assuming you're on a Windows machine)
    I have downloaded codeblocks, however can't seem to get it to compile into an EXE

  16. #14

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,528
    Thank Post
    1,460
    Thanked 1,214 Times in 823 Posts
    Rep Power
    724
    Quote Originally Posted by nephilim View Post
    I have downloaded codeblocks, however can't seem to get it to compile into an EXE
    Does it execute if you click "Build and Run" or is it throwing an error?

    If it runs, the exe has been created but finding it could be awkward. Easiest way is create a new project, console application, set the path. Then put the code in to "main.cpp" and build. Open up the folder where you created the project, and look in "bin\Debug" to find your exe

    EDIT: when you're sure it's working, you should change the build target to "Release" to cut out unnecessary debug symbols which in turn reduces the footprint of the exe (this will be built in "bin\Release")
    Last edited by LosOjos; 26th March 2013 at 03:41 PM.

  17. #15


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,479
    Thank Post
    867
    Thanked 851 Times in 673 Posts
    Rep Power
    197
    Are you absolutely sure you don't want it done in Perl?

  18. Thanks to tom_newton from:

    mac_shinobi (26th March 2013)

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. PlEEEESSSSSEEEE Help - Quick time
    By agiles in forum General Chat
    Replies: 8
    Last Post: 24th February 2013, 01:13 PM
  2. QUICK - Promethean Presentation help!
    By Dafty in forum AV and Multimedia Related
    Replies: 1
    Last Post: 11th February 2009, 09:54 AM
  3. NEED HELP QUICK! - EXPLORER.EXE NOT LOADING
    By WithoutMotive in forum Windows
    Replies: 18
    Last Post: 18th October 2008, 05:17 PM
  4. Quick help
    By imiddleton25 in forum EduGeek Joomla 1.5 Package
    Replies: 1
    Last Post: 22nd September 2008, 09:36 AM
  5. Setting up ISA 2004 quick help guide please.
    By tosca925 in forum Windows
    Replies: 1
    Last Post: 9th August 2006, 08:46 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •